2016-11-10 03:33
浏览 26


I am attempting to learn APIs and trying with the Amazon's AWSECommerceService. Using the XML below, I am trying to parse out specific values. In particular, I would like to get a value that is within a nest such as the number with . I thought I could do this with PHP SimpleXML but I am having a hard time doing this. Why won't this code work?

$xml=simplexml_load_file("test.xml") or die("Error: Cannot create object");
echo $xml->ItemLookupResponse[0]->Offers->TotalOffers . "<br>";

图片转代码服务由CSDN问答提供 功能建议

我正在尝试学习API并尝试使用亚马逊的AWSECommerceService。 使用下面的XML,我试图解析具体的值。 特别是,我想获得一个嵌套在一个嵌套中的值,例如数字。 我以为我可以用PHP SimpleXML做到这一点,但我很难做到这一点。 为什么这段代码不起作用?

 $ xml = simplexml_load_file(“test.xml”)或die(“错误:无法创建对象”)  ; 
echo $ xml-&gt; ItemLookupResponse [0]  - &gt; Offers-&gt; TotalOffers。  “&lt; br&gt;”; 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dougaoshang0237 2016-11-10 04:52

    Your simpleXML root is ItemLookupResponse so change

    echo $xml->ItemLookupResponse[0]->Offers->TotalOffers . "<br>";


    echo $xml->Items->Item->Offers->TotalOffers . "<br>";
    打赏 评论

相关推荐 更多相似问题