Asked By Karl Prosser[MVP]
16-Nov-07 02:32 AM

Xmldocument is a type that Powershell adapts. so it can do some special
things on it.. for my example i'll use your same document but i won't
load it from file i will create it with a typecast but it should work
the same
$doc = [xml]'<Envelope>hello world</Envelope>'
if you do $doc.gettype()you'll notice its still a system.xml.Xmldocument
however some of the properties of that class are hidden from powershell
are some more added. Notably if you do
$doc | get-member you'll see an Envelope. Powershell actually adapts the
contents of hte xml document as properties so you can simply do..
$doc.envelope
or even
$doc.envelope.body
which will return the XmlNodes XmlElements etc.
however what if you happened to have an xml node called innertext, you'd
have a conflict, thus powershell hides a bunch of the build in properties
if you run
$doc.SelectSingleNode("//Body")
you'll notice you actually get results in your console. its just you
can't access the innertext.. well with adapted types in powershell you
can always get the underlying dotnet objects properties and methods with
.psbase
$doc.SelectSingleNode("//Body").psbase.innertext
will do the job
but also you could do
$doc.SelectSingleNode("//Body").get_Innertext()
or a property powershell adds #text
$doc.SelectSingleNode("//Body")."#text"
Hope this helps.