gpt4 book ai didi

php - 如何解析具有ns2元素的xml

转载 作者:行者123 更新时间:2023-12-02 20:50:00 26 4
gpt4 key购买 nike

$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><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0c4d5c3c4f08181c3c4c2d5d5c49eddc9" rel="noreferrer noopener nofollow">[email protected]</a></ordEmail>
<clearanceEmail><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9febfaecebdfaeaeecebedfafaebb1f2e6" rel="noreferrer noopener nofollow">[email protected]</a></clearanceEmail >
<dlvCstType>03</dlvCstType>
<dlvNo>140065055</dlvNo>
<lstDlvCst>0</lstDlvCst>
<lstSellerDscPrc>0</lstSellerDscPrc>
<lstTmallDscPrc>0</lstTmallDscPrc>
<memID><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4f3b2a3c3b0f7e7e3c3b3d2a2a3b612236" rel="noreferrer noopener nofollow">[email protected]</a></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>
';

这是我的 xml,我想解析整个 xml,我尝试使用下面的代码

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

但它返回空对象。

SimpleXMLElement Object ( )

我尝试使用 children xml 解析,但结果相同。我关注了这个link也有但是​​没有成功

最佳答案

你可以使用这个:

$xml_data = str_replace("ns2:","",$xml_data);
$xml = simplexml_load_string($xml_data);
print_r($xml);

关于php - 如何解析具有ns2元素的xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42511817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com