SetChildElementByAttr (QTP, TestComplete, VBScript)
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

