如何从如下所示的亚马逊 MWS XML 文件中提取值?
可悲的是,我对 PHP(或 XML)不是很好。我一直在阅读/尝试在我能找到的所有网站上找到的所有内容,但我认为我无法胜任这份工作。
我尝试过 DOM、simpleXML、命名空间等,但一定是完全搞错了。
我试过这段代码:
$response = $service->GetMyPriceForASIN($request);
$dom = new DOMDocument();
$dom->loadXML($response->toXML());
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->saveXML();
$x = $dom->documentElement;
foreach ($x->childNodes AS $item) {
print $item->nodeName . " = " . $item->nodeValue . "<br>";
}
但是它只从最外层的节点返回此数据,如下所示:
GetMyPriceForASINResult = xxxxxxxxxxxB07DNYLZP5USD9.97USD9.97USD0.00USD15.99AMAZONNewNewxxxxxxxxxxxxxDazzle Tattoos ResponseMetadata = xxxxxxxxxxxxxxxxxxxxxxxx
我只是想得到的是 [Offers] 节点下的子项的货币和价格。
<?xml version="1.0"?>
<GetMyPriceForASINResponse
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetMyPriceForASINResult ASIN="B07DNYLZP5" status="Success">
<Product>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>xxxxxxxxxxxxxxxxxx</MarketplaceId>
<ASIN>B07DNYLZP5</ASIN>
</MarketplaceASIN>
</Identifiers>
<Offers>
<Offer>
<BuyingPrice>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>9.97</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>9.97</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</BuyingPrice>
<RegularPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>15.99</Amount>
</RegularPrice>
<FulfillmentChannel>AMAZON</FulfillmentChannel>
<ItemCondition>New</ItemCondition>
<ItemSubCondition>New</ItemSubCondition>
<SellerId>xxxxxxxxxx</SellerId>
<SellerSKU>Dazzle Tattoos</SellerSKU>
</Offer>
</Offers>
</Product>
</GetMyPriceForASINResult>
<ResponseMetadata>
<RequestId>xxxxxxxxxxxxxxxxxxxxx</RequestId>
</ResponseMetadata>
</GetMyPriceForASINResponse>
更新
Nigel 提供的链接没有帮助 - 它基本上是一个信息概要。