edgel1k
edgel1k

Reputation: 53

Issue with XPath not returning a value

I am fairly new to using XPath and XQuery and I can't seem to figure out why I am not able to return the OrderID from the following XML, using this XPath statement:

//OrderID[1]/text()

Why does it not find the OrderID or go any deeper than using this XPath?

//soap:Body

Here is the XML:

<soap:Envelope xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <SubmitOnlineSearchResponse xmlns="http://eservices.diligenz.com/">
         <SubmitOnlineSearchResult>
            <return>
               <orderInfo>
                  <OrderID>75124507</OrderID>
               </orderInfo>
            </return>
         </SubmitOnlineSearchResult>
      </SubmitOnlineSearchResponse>
   </soap:Body>
</soap:Envelope>

Upvotes: 1

Views: 181

Answers (1)

kjhughes
kjhughes

Reputation: 111621

Because OrderID is in the http://eservices.diligenz.com/ namespace.

If you can modify the message, add

xmlns:di="http://eservices.diligenz.com/"

to soap:Envelope along with the other namespace declarations and change your XPath to

//di:OrderID[1]/text()

If you cannot modify the message, use the hosting environment's facilities for binding namespace prefixes to namespaces, and bind di to http://eservices.diligenz.com/ in order for the above XPath to work.

Upvotes: 2

Related Questions