preload

p_SetXMLElementTextByIndex (QTP, TestComplete, VBScript)

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

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

Description

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

Implementation

Private Function p_SetXMLElementTextByIndex(ByRef objXMLElement, ByVal intIndex, ByVal sValue)
 Dim objXMLDoc, objTextNode
  Dim objColl, Iter, IndexIter

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

  For Iter=IndexIter to intIndex
    Set objTextNode = objXMLDoc.CreateTextNode(sValue)
    objXMLElement.AppendChild(objTextNode)
  Next 
 
  p_SetXMLElementTextByIndex = 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.