开发者

IPhone-XPath query wont retrieve my node

开发者 https://www.devze.com 2023-02-20 00:21 出处:网络
I\'m using GData as my XML parser. I\'ve tried using an XPath query to retrieve a node - @\"//GetPlacesAutoCompleteResult\".

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>
                  开发者_JS百科          <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>


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消