Possible Duplicate:
Parse XML with Namespace using SimpleXML
PHP SimpleXML Namespace Problem
<?php
header("Content-Type: text/html; charset=utf-8");
$str = <<<ETO
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:bc="http://www.brightcove.tv/link" xmlns:dcterms="http://purl.org/dc/terms/">
<channel>
<item>
<title>Press Conference with Chairman of the FOMC, Ben S. Bernanke</title>
<link>http://link.brightcove.com/services/link/bcpid720309829001/bctid1414417812001?src=mrss</link>
<description>Chairman of the FOMC, Ben S. Bernanke, Washington, D.C.</description>
<pubDate>Thu, 26 Jan 2012 11:57:19 -0800</pubDate>
<media:player height="580" url="http://link.brightcove.com/services/link/bcpid720309829001/bctid1414417812001?src=mrss" width="440"/>
<media:thumbnail height="90" url="http://brightcove.vo.llnwd.net/d20/unsecured/media/66043936001/66043936001_1414432575001_fomc-presser-thumb.jpg?pubId=66043936001" width="120"/>
<media:thumbnail height="360" url="http://brightcove.vo.llnwd.net/d20/unsecured/media/66043936001/66043936001_1414432069001_fomc-presser-large.jpg?pubId=66043936001" width="480"/>
<bc:duration>4016</bc:duration>
</item>
<item>
<title>Press Conference with Chairman of the FOMC, Ben S. Bernanke</title>
<link>http://link.brightcove.com/services/link/bcpid720309829001/bctid1258170578001?src=mrss</link>
<description>Chairman of the FOMC, Ben S. Bernanke, Washington, D.C.</description>
<pubDate>Thu, 26 Jan 2012 08:21:02 -0800</pubDate>
<media:player height="580" url="http://link.brightcove.com/services/link/bcpid720309829001/bctid1258170578001?src=mrss" width="440"/>
<media:thumbnail height="90" url="http://brightcove.vo.llnwd.net/d16/unsecured/media/66043936001/66043936001_1014046968001_DSC-95132.jpg?pubId=66043936001" width="120"/>
<media:thumbnail height="360" url="http://brightcove.vo.llnwd.net/d16/unsecured/media/66043936001/66043936001_1014127979001_DSC-95132.jpg?pubId=66043936001" width="480"/>
<bc:duration>2897</bc:duration>
</item>
</channel>
</rss>
ETO;
$xmlObj = simplexml_load_string($str);
foreach($xmlObj->channel->item as $item){
echo $item->title.'<br />';
echo $item->link.'<br />';
echo $item->description.'<br />';
echo $item->pubDate.'<br />';
echo $item->xpath('media:player').'<br />';
echo $item->xpath('media:thumbnail',0)->url.'<br />';
echo $item->xpath('media:thumbnail',1)->url.'<br />';
echo $item->xpath('bc:duration').'<br />';
echo '<hr />';
}
?>
How to parse some node like media:player
,media:thumbnail
, bc:duration
? I met some wrong, 2 string array and 2 wrong...
Array
Warning: SimpleXMLElement::xpath() expects exactly 1 parameter, 2 given in E:\www\1.php on line 37
Warning: SimpleXMLElement::xpath() expects exactly 1 parameter, 2 given in E:\www\1.php on line 39
Array