开发者

What is wrong with XPath query in SOAP response

开发者 https://www.devze.com 2023-04-13 08:26 出处:网络
I need to create a xpath query that will return everything listed under availabilty element. <?xml version=\"1.0\" encoding=\"UTF-8\"?>

I need to create a xpath query that will return everything listed under availabilty element.

    <?xml version="1.0" encoding="UTF-8"?>
     <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
           <GetAvailableTimesResult xmlns="http://schemas.test.net/x/version2/2007/06/" resultcode="SearchOk">
      <Availability>
        <Result available="true" time="2011-10-17T17:00:00"/>
        <Result available="true" time="2011-10-17T17:15:00"/>
        <Result available="true" time="2011-10-17T17:30:00"/>
        <Result available="true" time="2011-10-17T17:45:00"/>
        <Result available="true" time="2011-10-17T18:00:00"/>
        <Result available="true" time="2011-10-17T18:15:00"/>
        <Result available="true" time="2011-10-17T18:30:00"/>
        <Result available="true" time="2011-10-17T18:45:00"/>
        <Result available="true" time="2011-10-17T19:00:00"/>
        <Result available="true" time="2011-10-17T19:15:00"/>
        <Result available="true" time="2011-10-17T19:30:00"/>
        <Result available="true" time="2011-10-17T19:45:00"/>
        <Result available="true" time="2011-10-17T20:00:00"/>
        <Result available="true" time="2011-10-17T20:15:00"/>
        <Result available="true" time="2011-10-17T20:30:00"/>
        <Result available="true" time="2011-10-17T20:45:00"/>
        <Result available="true" time="2011-10-17T21:00:00"/>
        <Result available="true" time="2011-10-17T21:15:00"/>
        <Result available="true" time="2011-10-17T21:30:00"/>
        <Result available="true" time="2011-10-17T21:45:00"/>
        <Result available="true" time="2011-10-17T22:00:00"/>
        <开发者_如何学GoResult available="true" time="2011-10-17T22:15:00"/>
        <Result available="true" time="2011-10-17T22:30:00"/>
             </Availability>
                 </GetAvailableTimesResult>
       </soap:Body>
 </soap:Envelope>

My xpath query returns malformed xpath expression error message, the query is as follows:

//xsi:[soap:body]//Availability


You need to define prefix for http://schemas.livebookings.net/x/version2/2007/06/ namespace in your XPath engine, e.g. prefix a, then:

//a:Availability

It will select a:Availability element.

Or you can use this XPath:

//*[local-name() = 'Availability']


I need to create a xpath query that will return everything listed under availabilty element

Use:

/*/Soap:Body/x:GetAvailableTimesResult/x:Availability/node()

Where in your program you have associated (registered) the "x" prefix with the "http://schemas.livebookings.net/Ingrid/version2/2007/06/" namespace.

This is the most FAQ in XPath.

Search for "XPath default namespace" to get more detailed explanation.


Thanks to @Kirill Polishchuk

However, if you want to extract only one value of the list, you can do:

//*[local-name() = 'Availability'][position()=1]

or for the last one:

//*[local-name() = 'Availability'][last()]


You need to provide correct namespace with your XPath. Hope following code block will help you.

 v_Value := DBMS_XMLDOM.GetNodeValue(XslProcessor.SelectSingleNode(v_RootNode,   '/soap:Envelope/soap:Body/GetLiveAnalysisIDSResponse[1]/AnalysisIDs[1]/guid[1]/text()'
   ,'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="https://www.dummynet.net/"')); 

This code worked for me when extracting node value from SOAP response XML.

0

精彩评论

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

关注公众号