【问题标题】:IPhone-XPath query wont retrieve my nodeiPhone-XPath 查询不会检索我的节点
【发布时间】:2011-07-24 07:16:48
【问题描述】:

我使用 GData 作为我的 XML 解析器。 我尝试使用 XPath 查询来检索节点 - @"//GetPlacesAutoCompleteResult"。 但 getNodesForXPath 不返回任何节点。

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

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

这是我的 .xml 文件(来自对 .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>

【问题讨论】:

  • 此常见问题解答的众多副本之一:libxml2 error with namespaces and xpath
  • 你总是可以尝试像这样访问它:[Document nodesForXPath:@"//*[name()='GetPlacesAutoCompleteResult']" error:&amp;error];

标签: iphone xml web-services xpath gdata


【解决方案1】:

对于&lt;GetPlacesAutoCompleteResponse xmlns="http://xxxxxxx.com/xxxxxx/webservice"&gt;&lt;GetPlacesAutoCompleteResult&gt;,您在范围内有一个默认命名空间声明,因此假设您使用XPath 1.0,您需要将前缀绑定到命名空间URI http://xxxxxxx.com/xxxxxx/webservice 并使用该前缀来限定元素名称。例如,如果前缀是ws,那么您将使用//ws:GetPlacesAutoCompleteResult

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

【讨论】:

    猜你喜欢
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    相关资源
    最近更新 更多