我已经设法使用PHP创建XML文档。我现在想用PHP来循环访问xml文档并适当地显示它。这是我已经有的代码,但似乎没有工作。使用PHP处理XML
PHP循环
<?php
$rss2 = simplexml_load_file('food.xml');
print "<h3>XML document processed with PHP</h3>";
foreach ($rss2->xml->item as $item){
print "Title: ". $item->name."<br>";
print "Link: <a href=".$item->link.">".$item->link."</a><br>";
print "Description: ". $item->description."<br>";
print "<hr />";
}
?>
XML文档
<?xml version="1.0"?>
<xml>
<item>
<name>Food home page</name>
<link>http://www.food.com/</link>
<description>home cooking inspiration</description>
</item>
<item>
<name>Popular recipes</name>
<link>http://www.food.com/recipes-popular</link>
<description>Popular home food recipes</description>
</item>
<item>
<name>Pulled pork</name>
<link>http://www.food.com/recipe/pulled-pork-crock-pot-131018</link>
<description>Crock pot pulled pork recipe</description>
</item>
</xml>
任何人的帮助将不胜感激 感谢
RSS的文档元素应该是“rss”而不是“xml”。 * BTW * – ThW 2014-11-22 12:02:46