当前位置: 动力学知识库 > 问答 > 编程问答 >

html - 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?

网友答案:

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/>';
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: