<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function get_firstchild(n) {
var x = n.firstChild;
while (x.nodeType != 1) {
x = x.nextSibling;
}
return x;
}
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = get_firstchild(xmlDoc);
var y = get_firstchild(xmlDoc.documentElement);
document.getElementById("demo").innerHTML =
"Nodename: " + x.nodeName +
" (nodetype: " + x.nodeType + ")<br>" +
"Nodename: " + y.nodeName +
" (nodetype: " + y.nodeType + ")<br>";
}
</script>
</body>
</html>