运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { showResult(xhttp.responseXML); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); function showResult(xml) { var txt = ""; path = "/bookstore/book/title" if (xml.evaluate) { var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null); var result = nodes.iterateNext(); while (result) { txt += result.childNodes[0].nodeValue + "<br>"; result = nodes.iterateNext(); } // Code For Internet Explorer } else if (window.ActiveXObject || xhttp.responseType == "msxml-document") { xml.setProperty("SelectionLanguage", "XPath"); nodes = xml.selectNodes(path); for (i = 0; i < nodes.length; i++) { txt += nodes[i].childNodes[0].nodeValue + "<br>"; } } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>