iPhone-XPath 查询不会检索我的节点

发布于 2024-10-27 09:06:15 字数 3790 浏览 3 评论 0原文

我使用 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>

I'm using GData as my XML parser.
I've tried using an XPath query to retrieve a node -
@"//GetPlacesAutoCompleteResult".
but getNodesForXPath doesn't return any nodes.

so I'm asking, what's wrong with the query I typed in?

P.S
I'm only looking for a way to find out if the node exists or not, I care not about it's child nodes.

here is my .xml file (a result from a soap query to an .ASMX Web-Service).

<?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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-11-03 09:06:15

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

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

Well with <GetPlacesAutoCompleteResponse xmlns="http://xxxxxxx.com/xxxxxx/webservice"><GetPlacesAutoCompleteResult> you have a default namespace declaration in scope so assuming you use XPath 1.0 you need to bind a prefix to the namespace URI http://xxxxxxx.com/xxxxxx/webservice and use that prefix to qualify element names. For example if the prefix is ws then you would use //ws:GetPlacesAutoCompleteResult.

How you bind a prefix to a namespace URI depends on the XPath API you use, I am not familiar with GData so I can't help you with a code sample.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文