Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/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
Xml XPath//运算符不工作_Xml_Powershell_Xpath - Fatal编程技术网

Xml XPath//运算符不工作

Xml XPath//运算符不工作,xml,powershell,xpath,Xml,Powershell,Xpath,假设我有一个简单的XML文档,如下所示: <a> <b> <c>blah</c> <c>blah</c> <d>blargh</d> </b> </a> 尽管本例本身有效,但类似的概念并没有在XML文档中返回任何内容: <?xml version="1.0" encoding="utf-8"?> <Response xmlns="h

假设我有一个简单的XML文档,如下所示:

<a>
  <b>
   <c>blah</c>
   <c>blah</c>
   <d>blargh</d>
  </b>
</a>
尽管本例本身有效,但类似的概念并没有在XML文档中返回任何内容:

<?xml version="1.0" encoding="utf-8"?>
<Response xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Copyright>Copyright © 2012 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
  <BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
  <StatusCode>200</StatusCode>
  <StatusDescription>OK</StatusDescription>
  <AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
  <TraceId>985236ecd4b04793ac26f72a218a3876|LAXM001505|02.00.127.100|</TraceId>
  <ResourceSets>
    <ResourceSet>
      <EstimatedTotal>1</EstimatedTotal>
      <Resources>
        <TrafficIncident>
          <Point>
            <Latitude>41.82048</Latitude>
            <Longitude>-88.20378</Longitude>
          </Point>
          <IncidentId>1</IncidentId>
          <LastModifiedUTC>2012-05-01T16:17:15.663Z</LastModifiedUTC>
          <StartTimeUTC>2011-05-01T19:46:00Z</StartTimeUTC>
          <EndTimeUTC>2012-11-11T14:00:00Z</EndTimeUTC>
          <Type>Construction</Type>
          <Severity>Minor</Severity>
          <Verified>true</Verified>
          <RoadClosed>false</RoadClosed>
          <Description>description here</Description>
          <DetourInfo />
          <LaneInfo>lane blockages possible</LaneInfo>
          <CongestionInfo />
        </TrafficIncident>
      </Resources>
    </ResourceSet>
  </ResourceSets>
</Response>

版权所有©2012 Microsoft及其供应商。版权所有。未经微软公司明确书面许可,不得访问本API,不得以任何方式使用、复制或传播本API的内容和任何结果。
http://dev.virtualearth.net/Branding/logo_powered_by.png
200
好啊
有效存款
985236ECD4B044793AC26F721A218A3876 | LAXM001505 | 02.00.127.100|
1.
41.82048
-88.20378
1.
2012-05-01T16:17:15.663Z
2011-05-01T19:46:00Z
2012-11-11T14:00:00Z
建设
少数的
真的
假的
描述在这里
车道可能堵塞

是否有人知道在不必指定完整路径的情况下选择
TrafficIncident
元素的正确语法?

元素位于名称空间中,因此您需要在该名称空间中搜索它们。谷歌搜索“XPath默认名称空间”,这是第一个常见问题。

元素位于名称空间中,因此您需要在该名称空间中搜索它们。谷歌搜索“XPath默认名称空间”,这是第一个常见问题。

这就是获取c节点所需的全部内容。显然,您忘记了名称空间;-)这就是获取c节点所需的全部内容。显然,您忘记了名称空间;-)
<?xml version="1.0" encoding="utf-8"?>
<Response xmlns="http://schemas.microsoft.com/search/local/ws/rest/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Copyright>Copyright © 2012 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
  <BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
  <StatusCode>200</StatusCode>
  <StatusDescription>OK</StatusDescription>
  <AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
  <TraceId>985236ecd4b04793ac26f72a218a3876|LAXM001505|02.00.127.100|</TraceId>
  <ResourceSets>
    <ResourceSet>
      <EstimatedTotal>1</EstimatedTotal>
      <Resources>
        <TrafficIncident>
          <Point>
            <Latitude>41.82048</Latitude>
            <Longitude>-88.20378</Longitude>
          </Point>
          <IncidentId>1</IncidentId>
          <LastModifiedUTC>2012-05-01T16:17:15.663Z</LastModifiedUTC>
          <StartTimeUTC>2011-05-01T19:46:00Z</StartTimeUTC>
          <EndTimeUTC>2012-11-11T14:00:00Z</EndTimeUTC>
          <Type>Construction</Type>
          <Severity>Minor</Severity>
          <Verified>true</Verified>
          <RoadClosed>false</RoadClosed>
          <Description>description here</Description>
          <DetourInfo />
          <LaneInfo>lane blockages possible</LaneInfo>
          <CongestionInfo />
        </TrafficIncident>
      </Resources>
    </ResourceSet>
  </ResourceSets>
</Response>