Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在powershell中打印xml元素的实际内容?_Xml_Powershell_Xml Parsing - Fatal编程技术网

如何在powershell中打印xml元素的实际内容?

如何在powershell中打印xml元素的实际内容?,xml,powershell,xml-parsing,Xml,Powershell,Xml Parsing,当尝试使用powershell解析xml文件中的各种数据时,能够查看各种元素的实际情况(用于调试等)将非常有用。所以如果我有这样的东西: [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 =

当尝试使用powershell解析xml文件中的各种数据时,能够查看各种元素的实际情况(用于调试等)将非常有用。所以如果我有这样的东西:

[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}]"

我希望能够看到$items和$node的内容,但我得到的只是System.Xml.XmlDocument或System.Xml.xmlement。当我尝试使用items.Value或items.InnerText时,它们显示为空,那么如何打印这些元素的实际文本呢?

签出。具体来说,属性。我怀疑您在寻找
.InnerXml
.OuterXml

我得到了所有这些的空返回,即使${node.IsEmpty}返回空值。。。还是我打印的不正确?我对powershell一点也不了解。请尝试使用子表达式:
Write Output“$($items.OuterXml)$($node.OuterXml)”
OK,这似乎很有效,是否有使用${}vs$()等的指南?${}是一个有界变量,$()是子表达式$var与${var}相同