When trying to parse various data from an xml file using powershell it would be useful to be able to see what various elements actually are, for debugging and such. So if I have something like this:
[xml]$xmldoc = Get-Content doc.xml
$node = $xmldoc.SelectSingleNode("contents/some/path/items/item[name='itemname']")
$items = $xmldoc.contents.some.path.items
write-host "items = [${items}], node = [${node}]"
I'd like to be able to see contents of $items and $node, but all I get is System.Xml.XmlDocument or System.Xml.XmlElement. When I tried to use items.Value or items.InnerText they show up empty, so how do I print actual text of those elements?
Check out the XmlElement
class. Specifically, the properties. I suspect you're after .InnerXml
or .OuterXml
.
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