User Tools

Site Tools


Sidebar

wap:wap

WAP - Internet Applications

Snippets

  • xpath example - showResult modification
<!DOCTYPE html>
<html>
<body>
 
<p id="demo"></p>
 
<script>
var path = "/*";
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 = "";
    var s = new XMLSerializer();
    if (xml.evaluate) {
        var nodes = xml.evaluate(path, xml, null, XPathResult.ANY_TYPE, null);
        var result = nodes.iterateNext();
        while (result) {
            txt += "<b>" + result + " : " + result.tagName + "</b></br>"
            txt += result.childNodes[0].nodeValue + "<br>";
            txt += s.serializeToString(result) + "<br><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>
wap/wap.txt · Last modified: 2017/02/20 15:57 by george