1
投入HTML頁面,我需要通過包含信息,但一次一個,並顯示在HTML頁面中的XML文件中讀取。它需要像在<div>
以及<p>
的形式內的HTML中一樣滾動顯示。有人能幫我解決這個問題嗎?讀取XML的內容和使用JavaScript
abc.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<projects>
<project>
<flag>1</flag>
<name>Project 1</name>
<descp> Short description. </descp>
<rating> 6 </rating>
<link> URL1 </link>
</project>
<project>
<flag>1</flag>
<name>Project 2</name>
<descp> Short description. </descp>
<rating> 9 </rating>
<link> URL2 </link>
</project>
<project>
<flag>1</flag>
<name>Project 3</name>
<descp> Short description. </descp>
<rating> 4 </rating>
<link> URL3 </link>
</project>
<project>
<flag>1</flag>
<name>Project 4</name>
<descp> Short description. </descp>
<rating> 5 </rating>
<link> URL4 </link>
</project>
</projects>
的JavaScript:
<script type="text/javascript">
window.onload = timer;
function timer() {
var xmlDoc=new ActiveXObject("MSXML.DOMDocument");
xmlDoc.async="false";
xmlDoc.load("./gsss_hp.xml");
var projects = xmlDoc.documentElement;
var project = projects.childNodes(0);
var numPro = projects.childNodes.length; // to find number of projects entered in the file
for(var i=0; i<numPro; i++){
for(var j=0; j<100000;j++){j+=18; j-=18; for(var z=0;z<5000;z++){}} /* do noting for nested loops */
show(i);
}
}
function show(num) {
var xmlDoc=new ActiveXObject("MSXML.DOMDocument");
xmlDoc.async="false";
xmlDoc.load("./gsss_hp.xml");
var projects = xmlDoc.documentElement;
var project = projects.childNodes(num);
var attr = project.childNodes.length;
for(var i=0;i<attr;i++){
var txt = xmlDoc.getElementsByTagName("project")[0].childNodes[i].nodeValue;
txt = txt + "<br />";
var idPos;
if(i==1) { idPos = "name"; }
else
if(i==2) { idPos = "descp"; }
else
if(i==3) { idPos = "rating"; }
else
if(i==4) { idPos = "link"; }
document.getElementById(idPos).innerHTML = txt;
}
}
</script>
http://www.google.com/search?q=news+scroller+xml – mplungjan