【问题标题】:XMLReader not reading in all elements requestedXMLReader 未读取请求的所有元素
【发布时间】:2012-07-10 09:55:27
【问题描述】:

所以我有这个 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......

干杯

【问题讨论】:

  • 在帖子中添加了错误:)
  • 我认为某些元素缺少描述..你能检查一下吗?

标签: php xml xmlreader


【解决方案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;

这会奏效。享受吧。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    相关资源
    最近更新 更多