编辑下面的代码:【加编码】
<html> <head> <script src="/demo/loadxmldoc.js"> </script> </head> <body> <script> //check if the last node is an element node function get_lastchild(n) { x=n.lastChild; while (x.nodeType!=1) { x=x.previousSibling; } return x; } xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.documentElement; lastNode=get_lastchild(x); for (i=0;i<lastNode.childNodes.length;i++) { if (lastNode.childNodes[i].nodeType==1) { //Process only element nodes document.write(lastNode.childNodes[i].nodeName); document.write(" = "); document.write(lastNode.childNodes[i].childNodes[0].nodeValue); document.write("<br>"); } } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂