I can't find the right JavaScript method to access the attribute values I want from an xml file, using XPath in FireFox. Here's the sample xml:
<book category="cooking">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>
<book category="children">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>
I have viewed the other answers to previous questions (Getting attribute using XPath), but I can't seem to adapt them to work with my code.
Here's what I'm using (taken from the w3schools site):
<html>
<body>
<p id="demo"></p>
<p id="demo2"></p>
<script>
// from here: https://www.w3schools.com/xml/tryit.asp?filename=try_xpath_select_cdnodes
// new xmlhttprequest object
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        //call showResult function, pass response to request to it (i.e. the page we want to scrape)
        showResult(xhttp.responseXML);
    }
};
// initialise request with method and URL
xhttp.open("GET", "book.html", true);
// run request
xhttp.send(); 
// function to get xpath result, interate over it and write to paragraph tag with demo id
function showResult(xml) {
    var txt = "";
    //this is the xpath bit, the code to grab the tag values we want
    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;
}
</body>
</html>
This returns Everyday Italian, Harry Potter. I'd like to adapt to return en, en.
Appreciate the current code is working as it should, I just can't figure out where to put something like getAttributes method. I don't really understand why the firefox loop is using the childNodes method either. Thanks.
 
    