首页 > 解决方案 > 使用 xpath 提取 xml 值

问题描述

让我们有以下 XML:

<rest:RESTResponse xmlns:rest="http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd"
                   statusCode="200">
   <rest:headers>
      <rest:header name="Date" value="Sun,10 Feb 2019 13:46:02 GMT"/>
      <rest:header name="Transfer-Encoding" value="chunked"/>
      <rest:header name="Content-Type" value="text/xml;charset=utf-8"/>
      <rest:header name="Server" value="Apache-Coyote/1.1"/>
   </rest:headers>
   <rest:payload contentType="text/xml">
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <soapenv:Body>
            <getBatchGroupStatusReturn xmlns="urn:siperian.api">
               <rowidBatchGroupLog>SVR1.ENYY</rowidBatchGroupLog>
               <batchGroupUid>BATCH_GROUP.BPD_STAGE</batchGroupUid>
               <startRunDate>2019-02-10T14:46:02.157+01:00</startRunDate>
               <runStatus>2</runStatus>
            </getBatchGroupStatusReturn>
         </soapenv:Body>
      </soapenv:Envelope>
   </rest:payload>
</rest:RESTResponse>

如何提取“runStatus”元素的值?我尝试了以下路径:

rest:RESTResponse/rest:payload/soapenv:Envelope/soapenv:Body/getBatchGroupStatusReturn/runStatus

,但这仅在我从父元素中删除 xmlns="urn:siperian.api" 时才有效。但我不能对收到的回复做任何改变。

标签: xmlxpath

解决方案


推荐阅读