2011-03-28 57 views
0

我正在使用GData作为我的XML解析器。 我试过使用XPath查询来检索节点 - @“// GetPlacesAutoCompleteResult”。 但getNodesForXPath不返回任何节点。IPhone-XPath查询不会检索我的节点

所以我问,我输入的查询有什么问题?

P.S 我只是在寻找一种方法来找出节点是否存在,我不在乎它是否是子节点。

这里是我的.xml文件(从soap查询到.ASMX Web服务的结果)。

<?xml version="1.0" encoding="UTF-8"?> 
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <GetPlacesAutoCompleteResponse 
     xmlns="http://xxxxxxx.com/xxxxxx/webservice"> 
      <GetPlacesAutoCompleteResult> 
       <xs:schema id="NewDataSet" 
       xmlns="" 
       xmlns:xs="http://www.w3.org/2001/XMLSchema" 
       xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
        <xs:element name="NewDataSet" 
           msdata:IsDataSet="true" 
           msdata:UseCurrentLocale="true"> 
         <xs:complexType> 
          <xs:choice minOccurs="0" 
             maxOccurs="unbounded"> 
           <xs:element name="Table"> 
            <xs:complexType> 
             <xs:sequence> 
              <xs:element name="ID" 
                 type="xs:long" 
                 minOccurs="0"/> 
              <xs:element name="FullName" 
                 type="xs:string" 
                 minOccurs="0"/> 
              <xs:element name="PlaceTypeID" 
                 type="xs:int" 
                 minOccurs="0"/> 
             </xs:sequence> 
            </xs:complexType></xs:element> 
          </xs:choice> 
         </xs:complexType></xs:element> 
       </xs:schema> 
       <diffgr:diffgram 
       xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" 
       xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> 
        <NewDataSet xmlns=""> 
         <Table diffgr:id="Table1" msdata:rowOrder="0"> 
          <ID>47393</ID> 
          <FullName>Yifat</FullName> 
          <PlaceTypeID>10</PlaceTypeID> 
         </Table> 
         <Table diffgr:id="Table2" msdata:rowOrder="1"> 
          <ID>48497</ID> 
          <FullName>Haifa</FullName> 
          <PlaceTypeID>10</PlaceTypeID> 
         </Table> 
         <Table diffgr:id="Table3" msdata:rowOrder="2"> 
          <ID>70827</ID> 
          <FullName 
          >Haifa - Central Bus Rishon</FullName> 
          <PlaceTypeID>120</PlaceTypeID> 
         </Table> 
        </NewDataSet> 
       </diffgr:diffgram> 
      </GetPlacesAutoCompleteResult> 
     </GetPlacesAutoCompleteResponse> 
    </soap:Body> 
</soap:Envelope> 
+0

这个FAQ的许多重复之一:[命名空间和xpath的libxml2错误](http://stackoverflow.com/questions/3135175/libxml2-error-with-namespaces-and-xpath) – 2011-03-28 15:48:17

+1

你总是可以尝试访问它像这样:'[Document nodesForXPath:@“// * [name()='GetPlacesAutoCompleteResult']”error:&error];' – 2011-03-28 16:30:34

回答

2

好与<GetPlacesAutoCompleteResponse xmlns="http://xxxxxxx.com/xxxxxx/webservice"><GetPlacesAutoCompleteResult>你有一个默认命名空间声明范围如此假设你使用XPath 1.0你需要绑定的前缀命名空间URI http://xxxxxxx.com/xxxxxx/webservice和使用前缀来限定元素名称。例如,如果前缀是ws,那么您将使用//ws:GetPlacesAutoCompleteResult

如何将前缀绑定到名称空间URI取决于您使用的XPath API,我不熟悉GData,因此我无法帮助您获取代码示例。