我有一个对象,我从亚马逊回应得到。就像这个对象从xml转换为simplexml_load_string
:
["@attributes"]=> array(2) {
["condition"]=> string(3) "new"
["fulfillmentChannel"]=> string(6) "Amazon"
}
我想获得属性的价值。 我该怎么办?!! 谢谢!
当我转换xml时,属性显示为[@attributes] ..这是xml的一部分:
<BuyBoxEligibleOffers>
<OfferCount condition="new" fulfillmentChannel="Amazon">1</OfferCount>
<OfferCount condition="new" fulfillmentChannel="Merchant">10</OfferCount>
</BuyBoxEligibleOffers>
答案 0 :(得分:0)
您可以使用attributes的SimpleXMLElement方法。
例如:
$source = <<<SOURCE
<BuyBoxEligibleOffers>
<OfferCount condition="new" fulfillmentChannel="Amazon">1</OfferCount>
<OfferCount condition="new" fulfillmentChannel="Merchant">10</OfferCount>
</BuyBoxEligibleOffers>
SOURCE;
$elements = simplexml_load_string($source);
foreach ($elements as $element) {
echo "condition: " . $element->attributes()->condition . ", fulfillmentChannel: " . $element->attributes()->fulfillmentChannel . "<br>";
}
将导致:
条件:new,fulfillmentChannel:亚马逊
条件:new,fulfillmentChannel:Merchant