p_SetXMLElementCommentByIndex (QTP, TestComplete, VBScript)

Categories: Source codeXML Data

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

Description

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

Implementation

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
 Next
 Set objXMLDoc = objXMLElement.OwnerDocument
 IndexIter = IndexIter + 1
 For Iter=IndexIter to intIndex
 Set objCommentNode = objXMLDoc.CreateComment(sValue)
 objXMLElement.AppendChild(objCommentNode)
 Next 
 p_SetXMLElementCommentByIndex = True
End Function

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