var xmlDoc = document.implementation.createDocument('', '', null);
xmlDoc.load("book.xml");
xmlDoc.onload=function()//注意要加载完后才能使用
{
var cNodes = xmlDoc.getElementsByTagName("book");
for(var i=0;i<cNodes.length;i++)
{
var str="第"+(i+1)+"个节点\n"
str+="=====属性=====\nid="+cNodes[i].getAttribute("id")+"\nsortID="+cNodes[i].getAttribute("id")+"\n\n";
str+="=====子节点===\ntitle="+cNodes[i].getElementsByTagName("title")[0].firstChild.nodeValue
+"\nauthor="+cNodes[i].getElementsByTagName("author")[0].firstChild.nodeValue;
alert(str);
}
}
xmlDoc.load("book.xml");
xmlDoc.onload=function()//注意要加载完后才能使用
{
var cNodes = xmlDoc.getElementsByTagName("book");
for(var i=0;i<cNodes.length;i++)
{
var str="第"+(i+1)+"个节点\n"
str+="=====属性=====\nid="+cNodes[i].getAttribute("id")+"\nsortID="+cNodes[i].getAttribute("id")+"\n\n";
str+="=====子节点===\ntitle="+cNodes[i].getElementsByTagName("title")[0].firstChild.nodeValue
+"\nauthor="+cNodes[i].getElementsByTagName("author")[0].firstChild.nodeValue;
alert(str);
}
}
http://topic.csdn.net/u/20070421/17/3f36137d-0839-4f71-a3dd-a6fbc2984f35.html