I'm editing an XML document with VBA code. I want to build up a new, nested set of elements and then use replaceChild to substitute this portion of XML for a similar, existing element. I am getting run-time error 438 when trying to insert a text node into my first new element.
I copied this approach from a tutorial example I found online so expected it to work without a hitch.
I'm trying to build up this section of XML:
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
</ConnectionProperties>
To build up the elements:
Dim NewElement As MSXML2.IXMLDOMElement
Dim NewNodeElement As MSXML2.IXMLDOMElement
Dim NewNodeText As MSXML2.IXMLDOMText
Set NewElement = xmlDoc.createNode(1, "ConnectionProperties", xmlNameSpace)
Set NewNodeElement = xmlDoc.createNode(1, "DataProvider", xmlNameSpace)
Set NewNodeText = xmlDoc.createTextNode("SQL")
NewNodeElement.appendChild (NewNodeText) <--- Get run-time error 438 here
NewElement.appendChild (NewNodeElement)
I get the run-time error attempting to insert the text value "SQL" into the DataProvider tag.
I expected the text to be inserted into the element but I get a run-time error instead.