AppendChildElements (QTP, TestComplete, VBScript)
Parent page: Service Functions – MSXMLDOM (QTP, TestComplete, VBScript)
Description
Append all child elements from the list (including their attributes, comments, text nodes) to XML node.
Implementation
Public Function AppendChildElements(ByRef objXMLSrc, ByRef objNodeList) Dim Iter, objNode If objXMLSrc is Nothing Then Set AppendChildElements = Nothing Exit Function End If For Iter=0 To objNodeList.length-1 Set objNode = objNodeList.Item(Iter) Call objXMLSrc.AppendChild(objNode) Next Set AppendChildElements = objXMLSrc End Function
Test Code
Set objXMLDoc = CreateXMLDOM("test") Set objXMLParent1 = CreateChildElementByName(objXMLDoc.DocumentElement, "Parent", "parent src node") Set objXMLParent2 = CreateChildElementByName(objXMLDoc.DocumentElement, "Parent", "parent dest node") Set objXMLNode = CreateChildElementByName(objXMLParent1, "Object", "") Call SetXMLElementProperty(objXMLNode, "#attr:name", -1, "Username") Call SetXMLElementProperty(objXMLNode, "#attr:id", -1, "u123") Set objXMLNode = CreateChildElementByName(objXMLParent1, "Object", "") Call SetXMLElementProperty(objXMLNode, "#attr:name", -1, "Password") Call SetXMLElementProperty(objXMLNode, "#attr:id", -1, "p123") Set objXMLNode = CreateChildElementByName(objXMLParent1, "Object", "") Call SetXMLElementProperty(objXMLNode, "#attr:name", -1, "Login") Call SetXMLElementProperty(objXMLNode, "#attr:id", -1, "l123") Set objXMLParent = CreateChildElementByName(objXMLDoc.DocumentElement, "Parent", "parent dest node") Set objXMLNodeList = objXMLParent1.SelectNodes("./Object") Set objXMLParent = AppendChildElements(objXMLParent1, objXMLNodeList) Set objXMLNodeList = objXMLParent.SelectNodes("./Object") Set objDictionary = XMLNodeSet2Dictionary(objXMLNodeList) sValue = ParametersToStr(objDictionary.Item(1)) If sValue <> "#innertext = , #text_1 = , @name = Username, @id = u123" Then Log.Error "AppendChildElements failed" End If