0

所以我有这个 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 已设置为“条目”

我只是不明白为什么,有什么想法吗?

错误是

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

干杯

4

1 回答 1

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;

这将起作用。享受。

于 2012-07-10T10:09:30.977 回答