XML if there is a namespace we will parse, for example:
<NS1:Createbillresponsexmlns:ns1="Http://neusoft.com"Xmlns:xsd="Http://www.w3.org/2001/XMLSchema"xmlns:soap="Http://schemas.xmlsoap.org/soap/envelope/"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance" ><ns1:out><ns1:OutVo> <ns1:strb2bcode xmlns= "http://neusoft.com" >am1432690905685938443</ns1:strb2bcode>/neusoft.com ">01< Span class= "Hljs-symbol" >:strflag><ns1< span= "" >:strhpcode xsi:nil=" true "xmlns= "http://neusoft.com"/><ns1:strreason Xmlns= "http://neusoft.com", product code is empty, the sales party code is empty </ns1:strreason>1:OUTVO> :out>:CREATEBILLRESPONSE>
method of parsing:
1 |
function parseNamespaceXml( $xmlstr ) |
4 |
$xmlstr = preg_replace( ‘/\sxmlns="(.*?)"/‘ , ‘ _xmlns="${1}"‘ , $xmlstr ); |
5 |
$xmlstr = preg_replace( ‘/<(\/)?(\w+):(\w+)/‘ , ‘<${1}${2}_${3}‘ , $xmlstr ); |
6 |
$xmlstr = preg_replace( ‘/(\w+):(\w+)="(.*?)"/‘ , ‘${1}_${2}="${3}"‘ , $xmlstr ); |
7 |
$xmlobj = simplexml_load_string( $xmlstr ); |
8 |
return json_decode(json_encode( $xmlobj ), true); |
PHP parsing XML with namespaces