The proper use of MSXML replaceChild

KasynoEl

New Member
I'm trying to replace a node in one XML document with a node from another XML document. I'm getting the following error: \[code\]Insert position node must be a Child of the node to insert under.\[/code\]This is a simplified version of my XML:XMLDOC1\[code\]<pages> <page id="1"> <content>First Document</content> </page></pages>\[/code\]The other XML document is the exact same in structure:XMLDOC2\[code\]<pages> <page id="1"> <content>Second Document</content> </page></pages>\[/code\]I need to replace the page node of the first document with the page node of the second document. My attempt looks like this:\[code\]firstNode = xmlDoc1.selectSingleNode("//page[@id=1]")secondNode = xmlDoc2.selectSingleNode("//page[@id=1]")xmlDoc1.replaceChild(firstNode, oldNode)\[/code\]Thanks.Solution\[code\]firstNode.parentNode.replaceChild(xmlDoc1.importNode(secondNode, true), firstNode)\[/code\]
 
Back
Top