preload

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)

Description

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

Implementation

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
  Next
 
  Set objXMLDoc = objXMLElement.OwnerDocument
  IndexIter = IndexIter + 1

  For Iter=IndexIter to intIndex
    Set objCDataNode = objXMLDoc.CreateCDATASection(sValue)
    objXMLElement.AppendChild(objCDataNode)
  Next 
 
  p_SetXMLElementCDataByIndex = True
  
End Function


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.