2
$xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<ns2:orders xmlns:ns2="http://skt.tmall.business.openapi.spring.service.client.domain">
<ns2:order>
<ordNo>201303285538019</ordNo>
<ordPrdSeq>1</ordPrdSeq>
<addPrdNo>0</addPrdNo>
<addPrdYn>N</addPrdYn>
<ordEmail>test@11street.my</ordEmail>
<clearanceEmail>test@11street.my</clearanceEmail >
<dlvCstType>03</dlvCstType>
<dlvNo>140065055</dlvNo>
<lstDlvCst>0</lstDlvCst>
<lstSellerDscPrc>0</lstSellerDscPrc>
<lstTmallDscPrc>0</lstTmallDscPrc>
<memID>test@11street.my</memID>
<memNo>25879997</memNo>
<ordAmt>0</ordAmt>
<ordCnQty>0</ordCnQty>
<ordDt>04-03-2014 10:40:32</ordDt>
<ordNm>Kil Jun Jeong</ordNm>
<ordOptWonStl>300000</ordOptWonStl>
<ordPayAmt>0</ordPayAmt>
<ordPrtblTel>010-2988-6401</ordPrtblTel>
<ordPrdStat>901</ordPrdStat>
<ordQty>0</ordQty>
<ordTlphnNo>070-7400-3141</ordTlphnNo>
<prdNm>test product name</prdNm>
<prdNo>233607759</prdNo>
<prdStckNo>1532843428</prdStckNo>
<rcvrBaseAddr>50929, Kuala Lumpur, Wilayah Persekutuan Kuala Lumpur
</rcvrBaseAddr>
<rcvrDtlsAddr>jl setia budi </rcvrDtlsAddr>
<rcvrMailNo>156010</rcvrMailNo>
<rcvrNm>Kil Jun Jeong</rcvrNm>
<rcvrTlphn>070-7400-3141</rcvrTlphn>
<selPrc>100000</selPrc>
<sellerDscPrc>0</sellerDscPrc>
<tmallDscPrc>0</tmallDscPrc>
</ns2:order>
</ns2:orders>            
';

This is my xml and I want to parse whole xml, I tried with the below code

$xml = simplexml_load_string($xml_data);
print_r($xml);

but its return empty object.

SimpleXMLElement Object ( )

I tried with children xml parsing but same result. I followed this link too but no success

Community
  • 1
  • 1
AZinkey
  • 5,209
  • 5
  • 28
  • 46
  • This question has been asked before, kindly check: [http://stackoverflow.com/questions/1575788/php-library-for-parsing-xml-with-a-colons-in-tag-names](http://stackoverflow.com/questions/1575788/php-library-for-parsing-xml-with-a-colons-in-tag-names) – Ibraheem Mar 01 '17 at 06:43
  • "I tried with children xml parsing but same result." - *what* did you try? Show us the code. If you only ever tried with `print_r`, then that's probably your problem - `print_r` cannot "see" SimpleXMLElements properly. Access the specific data you actually need instead (e.g. with a plain `echo`). – IMSoP Mar 03 '17 at 16:13

1 Answers1

5

You can use this :

$xml_data = str_replace("ns2:","",$xml_data);
$xml = simplexml_load_string($xml_data);
print_r($xml);
NoNamE
  • 66
  • 1
  • 3