7

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

2
  • 1
    I think it should be $XML.ImportNode($wconfig.SelectSingleNode ... blah instead of $wconfig.ImportNode($wconfig.SelectSingleNode Commented Jun 8, 2012 at 14:05
  • 1
    yep -.- that worked. seems that i misunderstood the concept of importNode(). If you want post this as an answer so i can accept it. Thanks a lot. Commented Jun 8, 2012 at 14:11

1 Answer 1

7

I think it should be $XML.ImportNode($wconfig.SelectSingleNode ... blah instead of $wconfig.ImportNode($wconfig.SelectSingleNode

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.