p_SetXMLElementCDataByIndex (QTP, TestComplete, VBScript)

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

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


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


Private Function p_SetXMLElementCDataByIndex(ByRef objXMLElement, ByVal intIndex,ByVal sValue)
 Dim objXMLDoc, objCDataNode
  Dim objColl, Iter, IndexIter

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

  For Iter=IndexIter to intIndex
    Set objCDataNode = objXMLDoc.CreateCDATASection(sValue)
  p_SetXMLElementCDataByIndex = 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.