我需要创建一个 xpath 查询,它将返回可用性元素下列出的所有内容。
<?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>
我的xpath查询返回malformed xpath expression错误信息,查询如下:
//xsi:[soap:body]//Availability
最佳答案
您需要在 XPath 引擎中为 http://schemas.livebookings.net/Ingrid/version2/2007/06/
命名空间定义前缀,例如前缀 a
,然后:
//a:Availability
它将选择 a:Availability
元素。
或者您可以使用这个 XPath:
//*[local-name() = 'Availability']
关于xml - SOAP 响应中的 XPath 查询有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7794362/