私はPHPの初心者です。私は以下のXMLファイルを持っています。私はコンポーネントを解析したいと思います。あなたが見ることができるように、コンポーネントタグはここで繰り返されます。私はsimplexml_load_string
を使用してHTTPリクエストからの応答を取得しています。このXMLスキーマはここで繰り返されます(<order>
</order>
)。私はすべてのループまたは直接アクセスを使用して解析したい。ループまたは直接アクセスを使用してネストされたxml simplexml_load_string/simple xmlオブジェクトを解析します
<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 = simplexml_load_string($xmlDoc);
foreach($xml->children() as $node) {
echo $node->AmazonOrderID . ", ";
echo $node->ShipmentID . ", ";
echo $node->SKU . ", ";
echo $node->Component . "<br>";
}
何を試しましたか?私たちはあなたのためのコードを記述しません。 – Flummox
PHPマニュアルにはこのような単純なXML文書を解析するのに十分なことが分かるはずの[単純な例のページ](http://php.net/manual/en/simplexml.examples-basic.php)があります。 – IMSoP