我需要通过XML文件阅读,该档案中含有Info,但一个时段,并用超文本显示。 它需要像在“密码”和“设计”;div>内,以<代码>和t;p>的形式出现。 有些人能够帮助我如何做到这一点?
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>
Java:
<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>