Zdravo! Now this one has been bugging me quite a lot... I'm trying to copy a couple of nodes from one XML file to another using powershell, and looked around the whole internets, but it seems that only on my pc the universal solution to the problem is not working. So this is the code I've got now:
#loading one document
$xml = New-Object XML
$xml.Load("C:\Inetpub\WWWroot\web.config")
#load another
$wconfig = New-Object XML
$wconfig.Load("C:\Users\foo\test.enc")
#now do what everyone on the internet says
$xml.DocumentElement.InsertAfter($wconfig.ImportNode($wconfig.SelectSingleNode($node), $true), $afterNode))
Anyone got any idea why this (and a couple of other alternatives like .Clone()) always return "The node to be inserted is from a different document context." Or just give me another alternative. Anything that works :D
Thanks
I think it should be
$XML.ImportNode($wconfig.SelectSingleNode
... blah instead of $wconfig.ImportNode($wconfig.SelectSingleNode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With