XMLReader不读取所有请求的元素

时间:2012-07-10 09:55:27

标签: php xml xmlreader

所以我有这个XML

<entry>
<id>ABC123</id>
<title type="text">title </title>
<author xmlns="http://www.w3.org/2005/Atom">
    <name>test.com</name>
</author>
<link rel="self" href="http://www.test.com/asdasd.html"/>
<updated>2012-07-04T06:12:15.337</updated>
<content type="xml">
    <listing systemId="thesystemid" url="www.myurl.com">
        <description>
            This is a description
        </description>
    </listing>
</content>
</entry>

我正在使用带有此代码的XMLReader,我正在使用这个来提取数据:

$url = $product->content->listing['url'];
$id = $product->id;
$name = $product->title;
$desc = $product->content->listing->description;

除了$ desc

之外,所有东西都被完全拉开了

$ product已设为'entry'

我只是看不出原因,有什么想法吗?

错误是

Notice: Trying to get property of non-object in......

干杯

1 个答案:

答案 0 :(得分:1)

检查这个

$aa= '<entry>
     <id>ABC123</id>
     <title type="text">title </title>
     <author xmlns="http://www.w3.org/2005/Atom">
     <name>test.com</name>
     </author>
     <link rel="self" href="http://www.test.com/asdasd.html"/>
     <updated>2012-07-04T06:12:15.337</updated>
     <content type="xml">
     <listing systemId="thesystemid" url="www.myurl.com">
     <description>
        This is a description
     </description>
     </listing>
     </content>
     </entry>';
  $xml = simplexml_load_string($aa);
  echo $xml->content->listing->description;

这会奏效。享受。