What's wrong with an XPath request in a SOAP response

I need to create an xpath request that will return everything listed in the 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"/> <Result 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 request returns an invalid xpath expression error message, the query looks like this:

 //xsi:[soap:body]//Availability 
+6
source share
4 answers

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

 //a:Availability 

He will select the a:Availability item.

Or you can use this XPath:

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

I need to create an xpath request that will return everything listed under the accessibility element

Using

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

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

This is the most frequently asked question in XPath.

Find the "default XPath namespace" for a more detailed explanation.

+1
source

Thanks @Kirill Polishchuk

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

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

or for the latter:

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

You need to provide the correct namespace using XPath. Hope the following code block helps 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 retrieving the node value from the SOAP XML response.

0
source

Source: https://habr.com/ru/post/899461/


All Articles