使用xpath从动态SOAP响应中获取值

时间:2014-09-30 08:56:43

标签: xml soap xpath

我需要使用Xpath从SOAP响应中提取值。这是SOAP Repsonse格式:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
         <ns1:getServiceInfosResponse xmlns:ns1="http://ws.commande.lcm.somecompany.com/">
             <return xmlns:ns2="http://ws.commande.lcm.somecompany.com/">
                <customer>
                    <userid>12545646546</userid>
                    <servicesNumber>3</servicesNumber>
                    <service>
                        <serviceid>257</serviceid>
                        <state>activated</state>
                        <counterValue></counterValue>
                        <parametersNumber>0</parametersNumber>
                    </service>
                    <service>
                        <serviceid>692</serviceid>
                        <state>activated</state>
                        <counterValue></counterValue>
                        <parametersNumber>0</parametersNumber>
                    </service>
                    <service>
                        <serviceid>1077</serviceid>
                        <state>activated</state>
                        <counterValue>0</counterValue>
                        <parametersNumber>0</parametersNumber>
                    </service>
                </customer>
            </return>
        </ns1:getServiceInfosResponse>
    </soap:Body>
</soap:Envelope>

我想获得counterValue标签的值,其中serviceid是1077。 这就是我所做的,但它不起作用:

/soap:Envelope/soap:Body/ns1:getServiceInfosResponse/return/customer/service/serviceid[text()='1077']/counterValue

和此:

/soap:Envelope/soap:Body/ns1:getServiceInfosResponse/return/customer/service[serviceid='1077']/counterValue

这是一个link用于直播检查器。

请检查出现了什么问题

1 个答案:

答案 0 :(得分:0)

确定问题出在SOAP文件中的命名空间,如ns1,最好的方法就是忽略它们 试试这个工作

  /soap:Envelope/soap:Body/*/*/customer/service[serviceid='1077']/counterValue