Adam Waite
Adam Waite

Reputation: 18855

SimpleXML parse get past colon PHP

Hi I want to access the value in an XML feed:

<entry>
<ilink:operation>store</ilink:operation>
<ilink:type>ondemand</ilink:type>
<id>736</id>
<updated>2012-03-13T11:27:32Z</updated>
<content type="application/xml">
   <media:content>
      <ilink:parent_id>8132</ilink:parent_id>
      <ilink:availability_start>2012-01-06T00:00:00Z</ilink:availability_start>
      <ilink:availability_end>2012-02-03T00:00:00Z</ilink:availability_end>
      <ilink:duration>PT0S</ilink:duration>
   </media:content>
</content>

But the colons are getting in the way. How do I access that? Here's my code:

$pictureBoxXMLFeed = simplexml_load_file('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml');

foreach($pictureBoxXMLFeed->entry as $value){

    $hey = ($value->children('content')->children('media', true)->content->children('ilink', true)->parent_id);
    echo $hey;
    echo '<br/>';
}

But I just get a list of errors. Please can someone help me get to it?

Upvotes: 0

Views: 1534

Answers (1)

Crashspeeder
Crashspeeder

Reputation: 4311

The XML as you posted it is syntactically incorrect. There's no closing </entry> tag and there are no namespace definitions in it. This caused many a warning when attempting to come up with an answer.

Once I fixed those issues in the XML I used the following to get what you seem to be looking for:

foreach($pictureBoxXMLFeed->xpath('//content') as $content){
    $hey = ($content->children('media', true)->content->children('ilink', true)->parent_id);
    echo $hey;
    echo '<br/>';
}

Upvotes: 3

Related Questions