How to print actual contents of xml elements in powershell?

Viewed 6486

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?

1 Answers
Related