我在下面有这个 xml 文件:-
<item>
<title>Troggs singer Reg Presley dies at 71</title>
<description>Reg Presley, the lead singer of British rock band The Troggs, whose hits in the 1960s included Wild Thing, has died aged 71.</description>
<link>http://www.bbc.co.uk/news/uk-21332048#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/uk-21332048</guid>
<pubDate>Tue, 05 Feb 2013 01:13:07 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/65701000/jpg/_65701366_65701359.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/65701000/jpg/_65701387_65701359.jpg"/>
</item>
<item>
<title>Horsemeat found at Newry cold store</title>
<description>Horse DNA has been found in frozen meat in a cold store in Northern Ireland, as Irish police investigate a third case of contamination.</description>
<link>http://www.bbc.co.uk/news/world-europe-21331208#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/world-europe-21331208</guid>
<pubDate>Mon, 04 Feb 2013 23:47:38 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/65700000/jpg/_65700000_002950295-1.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/65700000/jpg/_65700001_002950295-1.jpg"/>
</item>
<item>
<title>US 'will sue' Standard & Poor's</title>
<description>Standard & Poor's says it is to be sued by the US government over the credit ratings agency's assessment of mortgage bonds before the financial crisis.</description>
<link>http://www.bbc.co.uk/news/21331018#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa</link>
<guid isPermaLink="false">http://www.bbc.co.uk/news/21331018</guid>
<pubDate>Mon, 04 Feb 2013 22:45:52 GMT</pubDate>
<media:thumbnail width="66" height="49" url="http://news.bbcimg.co.uk/media/images/65701000/jpg/_65701717_mediaitem65699884.jpg"/>
<media:thumbnail width="144" height="81" url="http://news.bbcimg.co.uk/media/images/65701000/jpg/_65701718_mediaitem65699884.jpg"/>
</item>
现在,当我将输入节点作为“项目”来检索数据时,而不是显示所有项目节点,它只显示最后一个项目节点.....
我的代码是:-
$dom->load($url);
$link = $dom->getElementsByTagName($tag_name);
$value = array();
for ($i = 0; $i < $link->length; $i++) {
$childnode['name'] = $link->item($i)->nodeName;
$childnode['value'] = $link->item($i)->nodeValue;
$value[$childnode['name']] = $childnode['value'];
}
这里,$url 是我的 xml 页面的 url $tag_name 是节点的名称,在这种情况下它是“item”
我得到的输出是: -
US 'will sue' Standard & Poor's.Standard & Poor's says it is to be sued by the US government over the credit ratings agency's assessment of mortgage bonds before the financial crisis.http://www.bbc.co.uk/news/21331018#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa.http://www.bbc.co.uk/news/world-europe-21331208.Mon, 04 Feb 2013 22:45:52 GMT
这是最后一个标签的数据。我想要所有项目标签的数据,并且我希望数据采用这种格式:-
title :- US 'will sue' Standard & Poor's
description :- Standard & Poor's says it is to be sued by the US government over
the credit ratings agency's assessment of mortgage bonds before the financial crisis
我什至想要我的输出中的子节点的名称(如果有的话)......请帮帮我......