preload

SetChildElementByAttr (QTP, TestComplete, VBScript)

Posted by Albert Gareev on Aug 30, 2008 | Categories: Source codeXML Data

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

Description

Sets text value for the child XML node specified via XPath query.

Note: creates a new XML node if nothing was found.

Implementation

Public Function SetChildElementByAttr(ByRef objXMLParent, ByVal sTagName, ByVal sAttrName, ByVal sValue)
 Dim objNode

  sTagName = Trim(sTagName)
  sAttrName = Trim(sAttrName)
  sValue = CStr(sValue)

 If objXMLParent is Nothing Then
  Set SetChildElementByAttr = Nothing
  Exit Function
 End If

 Set objNode = objXMLParent.SelectSingleNode("./"&sTagName&"[@name='" & sAttrName &"']")
 If isNull(objNode) or (objNode is Nothing) Then
   Set objNode = CreateChildElementByName(objXMLParent, sTagName, sValue)
   Call SetXMLElementProperty(objNode, "#Attr:name", -1, sAttrName)
 End If
  
  Call SetXMLElementProperty(objNode, "#text", -1, sValue)
 
  Set SetChildElementByAttr = objNode
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.