Franco
Franco

Reputation: 2926

XMLReader not reading in all elements requested

So I have this 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>

I'm using XMLReader with this code and I'm pulling in the data using this:

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

Everything is being pulled in perfectly apart from $desc

$product has been set as 'entry'

I just cannot see why, any ideas?

Error is

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

Cheers

Upvotes: 0

Views: 212

Answers (1)

Tuhin Subhra Dey
Tuhin Subhra Dey

Reputation: 980

check this

$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;

This will work. Enjoy.

Upvotes: 1

Related Questions