p_SetXMLElementCommentByIndex (QTP, TestComplete, VBScript)

Posted by Albert Gareev on Jul 06, 2008 | Categories: Source codeXML Data

Parent page: Service Functions – MSXMLDOM (QTP, TestComplete, VBScript)


Iterate to index. Change value for existing comment.
Otherwise create new child nodes till index.


Private Function p_SetXMLElementCommentByIndex(ByRef objXMLElement, ByVal intIndex, ByVal sValue)
 Dim objXMLDoc, objCommentNode
  Dim objColl, Iter, IndexIter

  Set objColl = objXMLElement.ChildNodes
  IndexIter = -1
  For Iter=0 To objColl.length-1
    If objColl.Item(Iter).NodeName = "#comment" Then
      IndexIter = IndexIter + 1
      If IndexIter = intIndex Then
        objColl.Item(Iter).NodeValue = sValue
        p_SetXMLElementCommentByIndex = True
        Exit Function
      End If
    End If
  Set objXMLDoc = objXMLElement.OwnerDocument
  IndexIter = IndexIter + 1

  For Iter=IndexIter to intIndex
    Set objCommentNode = objXMLDoc.CreateComment(sValue)
  p_SetXMLElementCommentByIndex = True
End Function

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.