用PHP解析XML
这就是我的XML的样子用PHP解析XML,php,xml,Php,Xml,这就是我的XML的样子 <?xml version="1.0" encoding="UTF-8"?> <item> <date>May 2013</date> <html>http://www.link.to/html.html</html> </item> 2013年5月 http://www.link.to/html.html 我在PHP中实现了这一点,并且它可以正常工作 $fi
<?xml version="1.0" encoding="UTF-8"?>
<item>
<date>May 2013</date>
<html>http://www.link.to/html.html</html>
</item>
2013年5月
http://www.link.to/html.html
我在PHP中实现了这一点,并且它可以正常工作
$file = '../modules/xml/nl-archive.xml';
$xml = simplexml_load_file($file);
$string = '';
foreach($xml as $item){
$string .= '<a href="'.$item->html .'" ><li>'.$item->date .'</li></a>';
}
$file='../modules/xml/nl archive.xml';
$xml=simplexml\u load\u文件($file);
$string='';
foreach($xml作为$item){
$string.='';
}
只是想让date标签和html标签的内容显示在每个item标签上。我一直在谷歌上搜索和修补,没能把它弄对。我做错了什么 尝试将XML更改为具有子级的根,如:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<date>May 2013</date>
<html>http://www.link.to/html.html</html>
</item>
</items>
2013年5月
http://www.link.to/html.html
Php就像您拥有的一样好。尝试更改您的XML,使其具有一个包含以下子项的根:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<date>May 2013</date>
<html>http://www.link.to/html.html</html>
</item>
</items>
2013年5月
http://www.link.to/html.html
Php就像您拥有的一样好。Ohhhh!我知道
simplexml\u load\u file()
通常只加载根标记,因此我认为是否有根并不重要。现在完全有道理了。非常感谢!哦!我知道simplexml\u load\u file()
通常只加载根标记,因此我认为是否有根并不重要。现在完全有道理了。非常感谢!