`

dom4j DOM方式和SAX方式解析带有命名空间XML报文的不同

 
阅读更多

XML报文如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wst="http://wsTest">
   <soapenv:Header/>
   <soapenv:Body>
      <wst:add>
         <!--Optional:-->
         <wst:a>2</wst:a>
         <!--Optional:-->
         <wst:b>3</wst:b>
      </wst:add>
   </soapenv:Body>
</soapenv:Envelope>

 目标选取:Envelope-->Body-->add-->a

Dom方式:

document.selectNodes("//*[local-name()='a' and namespace-uri()='http://wsTest']");

 或者:

document.selectNodes("/soapenv:Envelope/soapenv:Body/wst:mixed/wst:person/xsd:age");

 SAX方式:

reader.addHandler("/Envelope/Body/add/b", bHandler);

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics