我想要元素RN的值(所以,20200121) (我在这里找到了一个示例并修改了它)

文件位于d:\test.xml
我试过了:
[xml] $xdoc = get-content “d:\test.xml”
$xdoc | Select-Xml “//RN.value” | % { $_.Node.InnerText } | select -Unique它会失败并返回错误
Select-Xml : Cannot validate argument on parameter 'Xml'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At line:1 char:10
+ $xdoc | Select-Xml “//RN” | % { $_.Node.InnerText } | select ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Select-Xml], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.SelectXmlCommand我也试过了:
[xml] $xdoc = get-content “d:\test.xml”
$xdoc | Select-Xml “//RN.value” | % { $_.Node.InnerText } | select -Unique,它既没有错误,也没有输出。
发布于 2020-06-09 21:35:35
这似乎是一个名称空间解析问题:
$values = $xdoc |Select-Xml '//top:RN/top:value' -Namespace @{top='http://www.test.int'}|%{$_.Node.InnerText} |Select -Unique这应该会起作用。
发布于 2020-06-09 23:14:34
有多种方式可以不引用名称空间:how to ignore namespaces with XPath
$xdoc.message.bamessage.rn.value
20200121
select-xml '//*[local-name()="value"]' test.xml | % node
#text
-----
20200121https://stackoverflow.com/questions/62283376
复制相似问题