tags:

views:

44

answers:

1

I have defined an XML string using

$str = "<a><b></b></a>"

Now I want to load it into a [xml] variable to be able to manipulate it's nodes etc. The row below results in an error...

$str = [xml]"<a><b></b></a>"

How do I do this?

+1  A: 

I found this article to be pretty good: http://www.pluralsight-training.net/community/blogs/dan/archive/2006/11/25/42506.aspx

And this one: http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-14-xml.aspx

For when XML needs to be handled in PowerShell


Your question seems to work for me. How about you post the error so we can see what is going on? I just added test inside my string to show I can access the value, but it should work without it too.

Yes I added test, but you can see my example worked Full Image


ANOTHER EDIT:

Casting a string also worked for me, so how about you show us some work since I can't reproduce your issue Again, I added test to show that I can access XML members Full Image


...and I ran it with your string and it worked fine... ...notice there was an empty return? Full Image

Urda
It's all about loading XML from a FILE. I want to load it from a STRING.
Crassy
How about you post the error your getting then, because I was able to load the string in my powershell just fine. Also take it easy on the caps, the references inside those articles STILL APPLY (see how annoying the caps are). I'll update my question for you
Urda
Answer updated, I don't see what you are breaking.
Urda