<rss version="2.0"
xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>Title of RSS feed</title>
<link>http://www.google.com</link>
<description>Details about the feed</description>
<pubDate>Mon, 24 Nov 08 21:44:21 -0500</pubDate>
<language>en</language>
<item>
<title>Article 1</title>
<description><![CDATA[How to use StackOverflow.com]]></description>
<link>http://youtube.com/?v=y6_-cLWwEU0</link>
<media:player url="http://youtube.com/?v=y6_-cLWwEU0" />
<media:thumbnail url="http://img.youtube.com/vi/y6_-cLWwEU0/default.jpg"
width="120" height="90" />
<media:title>Jared on StackOverflow</media:title>
<media:category label="Tags">tag1,tag2</media:category>
<media:credit>Jared</media:credit>
<enclosure url="http://youtube.com/v/y6_-cLWwEU0.swf"
length="233"
type="application/x-shockwave-flash"/>
</item>
</channel>
</rss>
我決定使用XMLReader解析我的大型XML文件。我有麻煩的每一項特別的縮略圖使用XMLReader解析媒體RSS
這裏面的數據是我的代碼
//////////////////////////////
$itemList = array();
$i=0;
$xmlReader = new XMLReader();
$xmlReader->open('XMLFILE');
while($xmlReader->read()) {
if($xmlReader->nodeType == XMLReader::ELEMENT) {
if($xmlReader->localName == 'title') {
$xmlReader->read();
$itemList[$i]['title'] = $xmlReader->value;
}
if($xmlReader->localName == 'description') {
// move to its textnode/child
$xmlReader->read();
$itemList[$i]['description'] = $xmlReader->value;
}
if($xmlReader->localName == 'media:thumbnail') {
// move to its textnode/child
$xmlReader->read();
$itemList[$i]['media:thumbnail'] = $xmlReader->value;
$i++;
}
}
}
////////////////
是它最好使用DOMXpath,因爲我是巨大的解析XML文件?我非常感謝你的建議。
Hooorayy !!感謝編輯。 :) – 2009-05-29 10:32:43