How to print the 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 which elements actually exist, for debugging, etc. Therefore, 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 would like to see the 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 appear blank, so how can I print the actual text of these elements?

+4
source share
1 answer

XmlElement. , . , .InnerXml .OuterXml.

+4

Source: https://habr.com/ru/post/1682956/


All Articles