SOAP响应中的XPath查询有什么问题

时间:2022-10-29 00:09:16

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

我需要创建一个xpath查询,它将返回在availabilty元素下列出的所有内容。

    <?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 query returns malformed xpath expression error message, the query is as follows:

我的xpath查询返回错误的xpath表达式错误消息,查询如下:

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

4 个解决方案

#1


15  

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

您需要在XPath引擎中为http://schemas.livebookings.net/ingrid/version2/2007/06/namespace定义前缀,例如,前缀a:

//a:Availability

It will select a:Availability element.

它将选择一个:可用性元素。

Or you can use this XPath:

也可以使用这个XPath:

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

#2


1  

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

我需要创建一个xpath查询,它将返回在availabilty元素下列出的所有内容

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.

在您的程序中,您已经将“x”前缀与“http://schemas.livebookings.net/Ingrid/version2/2007/06/”名称空间关联(注册)。

This is the most FAQ in XPath.

这是XPath中最常见的常见问题。

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

搜索“XPath默认名称空间”以获得更详细的解释。

#3


0  

Thanks to @Kirill Polishchuk

由于@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()]

#4


0  

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

您需要为XPath提供正确的名称空间。希望以下代码块可以帮助您。

 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.

当从SOAP响应XML提取节点值时,该代码为我工作。

#1


15  

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

您需要在XPath引擎中为http://schemas.livebookings.net/ingrid/version2/2007/06/namespace定义前缀,例如,前缀a:

//a:Availability

It will select a:Availability element.

它将选择一个:可用性元素。

Or you can use this XPath:

也可以使用这个XPath:

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

#2


1  

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

我需要创建一个xpath查询,它将返回在availabilty元素下列出的所有内容

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.

在您的程序中,您已经将“x”前缀与“http://schemas.livebookings.net/Ingrid/version2/2007/06/”名称空间关联(注册)。

This is the most FAQ in XPath.

这是XPath中最常见的常见问题。

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

搜索“XPath默认名称空间”以获得更详细的解释。

#3


0  

Thanks to @Kirill Polishchuk

由于@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()]

#4


0  

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

您需要为XPath提供正确的名称空间。希望以下代码块可以帮助您。

 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.

当从SOAP响应XML提取节点值时,该代码为我工作。