有一些代码
123.xml:
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<P2MessageServiceStatus>
<CONNECTION>CONNECTION_CONNECTED</CONNECTION>
<ROUTER>ROUTER_CONNECTED</ROUTER>
</P2MessageServiceStatus>
</SOAP:Body>
</SOAP:Envelope>
所以,我正在尝试使用名称Spaces获取价值。没有它它运行正常,但使用命名空间它什么都不做
$url='http://123.xml'
$xpath='/SOAP:Envelope/SOAP:Body/P2MessageServiceStatus/@CONNECTION'
$namespace='SOAP'
$wc = New-Object Net.WebClient
[xml]$xml_body = $wc.DownloadString($url)
$xmlvalue= Select-Xml -XPath $xpath -Xml $xml_body -Namespace @{ SOAP = 'http://test'}
$ xmlvalue将为空且没有错误,如何解决?
答案 0 :(得分:2)
这里有两件事:
@
。这对我有用:
$xml = [xml] (gc e:\1.txt )
$xpath='/SOAP:Envelope/SOAP:Body/P2MessageServiceStatus/CONNECTION'
$xmlvalue= Select-Xml -XPath $xpath -Xml $xml -Namespace @{ "SOAP" = 'http://schemas.xmlsoap.org/soap/envelope/'}
$xmlvalue