我有这个
<rss>
<channel>
<item>
<link>http://www1</link>
<title>Doe </title>
<description>Para </description>
</item>
</channel>
</rss>
和这个
<feed>
<article>
<link>http://www1</link>
<title>Doe </title>
<description>Para </description>
</article>
</feed>
如何使用相同的代码处理这两种xml。
我试试这个但是不起作用
$xml_root=$_GET['xml_root']; // $xml_root='channel'
$xml_item=$_GET['xml_item']; // $xml_item='item'
$xml= file_get_contents($xmlfile);
$xmldoc = new SimpleXmlElement($xml);
foreach ($xmldoc->$xml_root->$xml_item as $xmltree){
I received this: Warning: Invalid argument supplied for foreach() in
I try use
foreach ($xmldoc->$xml_root()->$xml_item() as $xmltree){
but doesn't work too
请帮帮我!!
答案 0 :(得分:0)
尝试使用simplexml_load_file
$xmlfile = "rss.xml"; // or feed.xml
$xml= simplexml_load_file($xmlfile);
$array = $xml->channel->item ? $xml->channel->item : $xml->article;
foreach($array as $value) {
echo $value->link;
}