• 0

[VB.NET] XML Append Child error


Question

I am attempting to insert xml from one file into a certain node of another file.

Dim XMLDom As New XmlDocument()
XMLDom.Load("Resources\default.xmlm vehicleNode As XmlNode = XMLDom.SelectSingleNode("//object[@name='vehicles']")

Dim xmlTest As New XmlDocument()
xmlTest.Load("Resources\Vehicles\boat.xmlm testNode As XmlNode = xmlTest.SelectSingleNode("//object[@id]") 

vehicleNode.AppendChild(testNode)

It seems to run fine until it gets to the AppendChild line which results in an exception "The node to be inserted is from a different document context." Any suggestions?

edit: NVM I figured it out.

You have to import the other node first

 	Dim XMLDom As New XmlDocument()
 	XMLDom.Load("Resources\default.xmlDim vehicleNode As XmlNode = XMLDom.SelectSingleNode("//object[@name='vehicles']")

 	Dim xmlTest As New XmlDocument()
 	xmlTest.Load("Resources\Vehicles\boat.xmlDim testNode As XmlNode = xmlTest.SelectSingleNode("//object[@id]")

 	Dim test As XmlNode = XMLDom.ImportNode(testNode, True)

 	vehicleNode.AppendChild(test)

	XMLDom.save("test.xml

Link to comment
https://www.neowin.net/forum/topic/903464-vbnet-xml-append-child-error/
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.