我正在使用Amazon API获取产品详细信息。我有一个这样的xml输出文件。我正在尝试解析xml代码以获取值。但是它只对某些对象有效,而对另一些对象无效。
<ItemLookupResponse
xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
<OperationRequest>...</OperationRequest>
<Items>
<Request>
<IsValid>True</IsValid>
<ItemLookupRequest>
<IdType>ASIN</IdType>
<ItemId>B008593O8S</ItemId>
<ResponseGroup>Images</ResponseGroup>
<ResponseGroup>ItemAttributes</ResponseGroup>
<ResponseGroup>Offers</ResponseGroup>
<VariationPage>All</VariationPage>
</ItemLookupRequest>
</Request>
<Item>
<ASIN>B008593O8S</ASIN>
<DetailPageURL>
https://www.amazon.in/Immortals-Meluha-Shiva-Trilogy-Book-
ebook/dp/B008593O8S?SubscriptionId=AKIAIM25C44CBBK52BEA&tag=compafridok-
43&linkCode=xm2&camp=2025&creative=165953&creativeASIN=B008593O8S
</DetailPageURL>
<SmallImage>
<URL>
https://images-eu.ssl-images-amazon.com/images/I/51K-Mo0AXDL._SL75_.jpg
</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">49</Width>
</SmallImage>
<MediumImage>
<URL>
https://images-eu.ssl-images-amazon.com/images/I/51K-Mo0AXDL._SL160_.jpg
</URL>
<Height Units="pixels">160</Height>
<Width Units="pixels">104</Width>
</MediumImage>
<LargeImage>
<URL>
https://images-eu.ssl-images-amazon.com/images/I/51K-Mo0AXDL.jpg
</URL>
<Height Units="pixels">500</Height>
<Width Units="pixels">326</Width>
</LargeImage>
</Item>
</Items>
`
例如,
$pxml = simplexml_load_string($response);
$title = $pxml->Items->Item->DetailPageURL; //Working
$link = $pxml->Items->Item->SmallImage->URL; //Not working
还有其他可用的方法吗?谢谢!