【发布时间】:2017-02-28 13:40:42
【问题描述】:
我已经生成了一个简单的 xml。我想在 xml 中添加命名空间/前缀有没有使用 php DomDocument 的方法。还是我需要使用core php替换标签并在xml中重新创建。
<?xml version="1.0" encoding="UTF-8"?>
<orderShipment>
<orderData>
<productId>1</productId>
<orderStatus>
<status>Shipped</status>
<statusQuantity>
<amount>1</amount>
</statusQuantity>
<trackingInfo>
<shipDateTime>Fri, 24 Feb 2017</shipDateTime>
<carrierName>UPS</carrierName>
<methodCode>Standard</methodCode>
<trackingNumber>123123123</trackingNumber>
<trackingURL>http://ups.com</trackingURL>
</trackingInfo>
</orderStatus>
</orderData>
</orderShipment>
预期输出
<?xml version="1.0" encoding="UTF-8"?>
<ns2:orderShipment>
<ns2:orderData>
<ns2:productId>1</ns2:productId>
<ns2:orderStatus>
<ns2:status>Shipped</ns2:status>
<ns2:statusQuantity>
<ns2:amount>1</ns2:amount>
</ns2:statusQuantity>
<ns2:trackingInfo>
<ns2:shipDateTime>Fri, 24 Feb 2017</ns2:shipDateTime>
<ns2:carrierName>UPS</ns2:carrierName>
<ns2:methodCode>Standard</ns2:methodCode>
<ns2:trackingNumber>123123123</ns2:trackingNumber>
<ns2:trackingURL>http://ups.com</ns2:trackingURL>
</ns2:trackingInfo>
</ns2:orderStatus>
</ns2:orderData>
</ns2:orderShipment>
【问题讨论】:
标签: php xml domdocument