简单教程
提交运行
代码编辑器:
<script> function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; } document.write("<ul>") var xml=loadXMLDoc("/static/exam/xmle/books.xml"); var path="/bookstore/book[price>35]/title"; // code for IE if (window.ActiveXObject) { var nodes=xml.selectNodes(path); for (i=0;i<nodes.length;i++) { document.write("<li>" + nodes[i].childNodes[0].nodeValue + "</li>"); } } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { var nodes=xml.evaluate(path, xml, null, XPathResult.ANY_TYPE,null); var result=nodes.iterateNext(); while (result) { document.write("<li>" + result.childNodes[0].nodeValue + "</li>"); result=nodes.iterateNext(); } } document.write("</ul>") </script>
运行结果: