I have a string variable containing XML that I would simply like to append to an IXMLDOMNode. Hilariously, this is the most primitive task, yet painfully unintuitive, in MSXML2. (I don't want to use XSLT).
My approach was:
Set xRoot = xDoc2.selectSingleNode("/ns:Root") 'destination parent
Set xNode = NodeFromXML(XMLstring) 'node to append
xRoot.appendChild xNode 'FAIL
----------------------------------------------
Private Function NodeFromXML(XMLstring As String) As IXMLDOMNode
'returns IXMLDOMNode of loaded XML string...
Dim Obj As New MSXML2.DOMDocument60
On Error GoTo handler
With Obj
.async = False
.loadXML XMLstring
Set NodeFromXML = .selectSingleNode("/")
End With
handler:
End Function
The problem with this is that my NodeFromXML function produces a node that is of node type 'DOCUMENT' and thus cannot be appended to an ELEMENT type node.
How should I achieve my goal?