如何从soap响应中获取所有元素列表

时间:2016-10-07 15:20:54

标签: powershell soap response

我是这个SOAP响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:anow="http://tempuri.org/AnoWebservice" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header />
  <soapenv:Body>
    <anow:AnoWebserviceResponse>
      <anow:result>
        <resultCode>0</resultCode>
      </anow:result>
      <anow:response>
        <DataView>
          <ERROR_CODE>NOER</ERROR_CODE>
          <SYS_FORZA>N</SYS_FORZA>
          <A>
            <B>0</B>
            <V>2016-10-06</V>
          </A>
        </DataView>
      </anow:response>
    </anow:AnoWebserviceResponse>
  </soapenv:Body>
</soapenv:Envelope>

实际上是使用

提取单个元素I的值
$value=Select-Xml -XPath $XPath -Xml $SOAPResponseFile -Namespace @{ "soapenv" = 'http://schemas.xmlsoap.org/soap/envelope/' ; "anow" = 'http://tempuri.org/AnoWebservice'}

我想提取每个节点的每个元素名称。 这意味着输出应该是:

ERROR_CODE
SYS_FORZA
B
V

我该怎么做?

提前谢谢

此致

克劳迪奥

1 个答案:

答案 0 :(得分:1)

$xpath = "//DataView//*"

Select-Xml -XPath $XPath -Xml $SOAPResponseFile -Namespace @{ "soapenv" = 'http://schemas.xmlsoap.org/soap/envelope/' ; "anow" = 'http://tempuri.org/AnoWebservice'} | foreach-object {$_.node.Name}