12

xpath解析带命名空间的xml(解析soap返回消息)

2018-03-13 15:53:00    1147533288    6485    原创



String ret = SoapUtil.send2(dataXml.asXML());//工具类返回soap报文,代码未贴出
Document doc = DocumentHelper.parseText(ret);
DefaultXPath xpath = new DefaultXPath("//tar:body/tar:record");
xpath.setNamespaceURIs(Collections.singletonMap("tar","http://www.jhlss.gov.cn/esb/TargetService"));

Node node = xpath.selectSingleNode(doc);


返回文本消息参考:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tar="http://www.jhlss.gov.cn/esb/TargetService">
   <soapenv:Header/>
   <soapenv:Body>
      <tar:executeResponse>
         <tar:routeId>?</tar:routeId>
         <tar:header>
            <tar:callerId>?</tar:callerId>
            <tar:userId>?</tar:userId>
         </tar:header>
         <tar:body>
            <!--Optional:-->
            <tar:record>123123</tar:record>
            <!--Zero or more repetitions:-->
            <tar:records>
               <tar:type>?</tar:type>
               <!--Zero or more repetitions:-->
               <tar:record>?</tar:record>
            </tar:records>
         </tar:body>
         <tar:signData>?</tar:signData>
      </tar:executeResponse>
   </soapenv:Body>
</soapenv:Envelope>


苏ICP备18038013号-1
蝉知 蝉知5.2