iPhone-XPath 查询不会检索我的节点
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
,您在范围内有一个默认的命名空间声明,因此假设您使用 XPath 1.0,您需要将前缀绑定到命名空间 URIhttp://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 URIhttp://xxxxxxx.com/xxxxxx/webservice
and use that prefix to qualify element names. For example if the prefix isws
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.