通过方法getElementsByTagName方法解析嵌套标记元素

时间:2017-07-31 12:04:25

标签: php xml xml-parsing getelementsbytagname

<Order>
<AmazonOrderID>406-6143419-7223518</AmazonOrderID>
<MerchantOrderID>406-6143419-7223518</MerchantOrderID>
<ShipmentID>DDNSkvgJN</ShipmentID>
<MarketplaceName>Amazon.in</MarketplaceName>
<Fulfillment>
<MerchantFulfillmentID>AFN</MerchantFulfillmentID>
<PostedDate>2017-07-22T08:31:18+00:00</PostedDate>
<Item>
<AmazonOrderItemCode>31251963544243</AmazonOrderItemCode>
<SKU>DZ-HA0T-A5GQ</SKU>
<Quantity>1</Quantity>
<ItemPrice>
<Component>
<Type>Principal</Type>
<Amount currency="INR">780.47</Amount>
</Component>
<Component>
<Type>Shipping</Type>
<Amount currency="INR">13.02</Amount>
</Component>
<Component>
<Type>Tax</Type>
<Amount currency="INR">174.78</Amount>
</Component>
</ItemPrice>
<ItemFees>
<Fee>
<Type>FBAPerUnitFulfillmentFee</Type>
<Amount currency="INR">-10.00</Amount>
</Fee>
<Fee>
<Type>FBAPerUnitFulfillmentFeeTax</Type>
<Amount currency="INR">-1.80</Amount>
</Fee>
<Fee>
<Type>FBAWeightBasedFee</Type>
<Amount currency="INR">-43.00</Amount>
</Fee>
<Fee>
<Type>FBAWeightBasedFeeTax</Type>
<Amount currency="INR">-7.74</Amount>
</Fee>
<Fee>
<Type>Commission</Type>
<Amount currency="INR">-135.83</Amount>
</Fee>
<Fee>
<Type>CommissionTax</Type>
<Amount currency="INR">-24.45</Amount>
</Fee>
<Fee>
<Type>FixedClosingFee</Type>
<Amount currency="INR">-20.00</Amount>
</Fee>
<Fee>
<Type>FixedClosingFeeTax</Type>
<Amount currency="INR">-3.60</Amount>
</Fee>
</ItemFees>
<Promotion>
<MerchantPromotionID>DCMS-3f4089f9-060b2c1e</MerchantPromotionID>
<Type>Principal</Type>
<Amount currency="INR">-156.25</Amount>
</Promotion>
<Promotion>
<MerchantPromotionID>IN Core Free Shipping 2015/04/08 23-48-5-108</MerchantPromotionID>
<Type>Shipping</Type>
<Amount currency="INR">-13.02</Amount>
</Promotion>
</Item>
</Fulfillment>
</Order>

我有以下xml结构,重复n次。我想提取对应于类型的所有金额,即Principal,Shipping(重复pl看下面),FixedClosingFee。我想通过嵌套的getElementbyTagname解析ex: - ItemPrice-&gt; Component-&gt;类型及其对应的Amount。

0 个答案:

没有答案