Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print actual contents of xml elements in powershell?

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?

like image 538
Maxim Avatar asked Aug 03 '17 15:08

Maxim


1 Answers

Check out the XmlElement class. Specifically, the properties. I suspect you're after .InnerXml or .OuterXml.

like image 80
G42 Avatar answered Nov 15 '22 03:11

G42