by Ritmo2k at 2013-02-14 10:16:54
I need to store the textual representation of a System.Xml.XmlDocument object into a variable, I see you can redirect the save() to the console, but how about a string variable?by MattG at 2013-02-14 16:52:03
Thanks!
Here’s an example of what I think you’re looking for:by Ritmo2k at 2013-02-14 17:07:00$Site = Invoke-WebRequest Recent Questions - Stack Overflow
The Save method has the following overloaded definitions:
$XMLFeed = [xml] $Site.Content
$StringWriter = New-Object IO.StringWriter
$XMLFeed.Save($StringWriter)
$RawOutput = $StringWriter.ToString()OverloadDefinitions
I chose System.IO.StringWriter which inherits from System.IO.TextWriter whose ToString method outputs the raw XML. This is the best approach I could come up with.
-------------------
void Save(string filename)
void Save(System.IO.Stream outStream)
void Save(System.IO.TextWriter writer)
void Save(System.Xml.XmlWriter w)
I hope this answers your question.
Ugh, much simpler than I finally arrived at! How do you enumerate the overload defs, I presume you have to hit the msdn docs on this class. I was trying to use get-member -force…by MattG at 2013-02-14 17:28:28
Thanks a ton!
My pleasure! You can see the overloaded definitions in powershell by typing any method name without parentheses. Some examples:by Ritmo2k at 2013-02-14 17:42:21$XMLFeed.Save
'hi'.Replace
(3).Equals
Thats pretty awesome, I am spoiled with the iPython console and a good IDE like PyCharm when working in Python.
Didn’t know that one existed!
Cheers!