Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <script> function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); try {xhttp.responseType="msxml-document"} catch(err) {} // Helping IE xhttp.send(""); return xhttp; } var x=loadXMLDoc("books.xml"); var xml=x.responseXML; path="/bookstore/book[price>35]/price"; // code for IE if (window.ActiveXObject || xhttp.responseType=="msxml-document") { xml.setProperty("SelectionLanguage","XPath"); nodes=xml.selectNodes(path); for (i=0;i<nodes.length;i++) { document.write(nodes[i].childNodes[0].nodeValue); document.write("<br>"); } } // code for Chrome, 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(result.childNodes[0].nodeValue); document.write("<br>"); result=nodes.iterateNext(); } } </script> </body> <!-- Mirrored from www.w3schools.com/xsl/tryit.asp?filename=try_xpath_select_pricenodes_35 by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 13 Mar 2016 11:03:25 GMT --> </html>
Result: