Skip to content Skip to sidebar Skip to footer

Unable To Retrieve A Sub-nodelist From A Nodelist In Javascript

So here's the deal: I'm trying to retrieve a NodeList object from an already existing NodeList. Here's a simplified XML example: C

Solution 1:

Thank you Teemu, I've managed to achieve what I wanted with a few tweaks in my Javascript code. I'll post it here so that maybe someone might find it helpful in the future:

functionparseXML(xmlString) {
    varNAME = 5; 
    var parser = newDOMParser();
    var xmlDoc = parser.parseFromString(xmlString, "text/xml");
    var products = xmlDoc.getElementsByTagName("product");

    for(var i = 0; i < products.length; i++){
        var nodeList = produtos[i].childNodes;
        $('#div_products').append(nodeList[NAME].textContent + "<br>");
    }

    $('#div_main').html($('#div_products').html());
} 

Please notice that 5 is the index of the DOM TextNode I wanted (the product name itself), hence:

var NAME = 5;

That would be all.

Post a Comment for "Unable To Retrieve A Sub-nodelist From A Nodelist In Javascript"