XmlHttpRequest In Javascript - not finding nodeValue's ???

Posted on 2005-05-12
Last Modified: 2008-01-09
I am playing around with XmlHttpRequest to add some nifty functionality to a CMS. My problem is that, using DOM, I CAN access the object.nodeName, but not the object.nodeValue. My first assumption was that my XML was not correctly formed, however I have checked a million times and it's fine. Here is what I'm working with:

                var req;
            function loadXMLDoc(url) {
                  // branch for native XMLHttpRequest object
                  if (window.XMLHttpRequest) {
                        req = new XMLHttpRequest();
                        req.onreadystatechange = processReqChange;
              "GET", url, true);
                        // branch for IE/Windows ActiveX version
                  } else if (window.ActiveXObject) {
                        req = new ActiveXObject("Microsoft.XMLHTTP");
                        if (req) {
                              req.onreadystatechange = processReqChange;
                    "GET", url, true);
                  else {
                        // do nothing

               function processReqChange() {
                  // only if req shows "loaded"
                  if (req.readyState == 4) {
                        // only if "OK"
                        if (req.status == 200) {
                        } else {
                              alert("There was a problem retrieving the XML data:\n" + req.statusText);

                // empty Topics select list content
            function clearFileList() {
                  document.getElementById('fileList').innerHTML = '';

               function appendToList(divi, value, content) {
                  var opt;
                  opt = divi;
                  opt.innerHTML = (opt.innerHTML + content);
            function buildFileList() {
                   var listdiv = document.getElementById("fileList");
                   var items = req.responseXML.getElementsByTagName("file");
                   // loop through <file> elements, and add each nested
                   // <title> element to List
                   for (var i = 0; i < items.length; i++) {
                                 // Finds TITLE element and outputs the value.
                         appendToList(listdiv, i, ('<li class="attFile" id="att'+ i +'"><a href="#">' + items[i].firstChild.nodeValue + '</a></li>'));

My XML file outputs this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

                  <title>Happy Lappy</title>

                  <description>Mums' great new laptop.</description>


                  <description>is this an image! i think it is!</description>



I've tried using getElementsByTagName() to find the "title" element, all sorts of crazy hair-brained stuff, but it just keeps outputing "undefined".

Any ideas? Can you see any errors in my code? Your help is most appreciated!
Question by:ucantblamem
    LVL 3

    Accepted Solution


    is the <file><title> element. The Text within that is within a Text Node. I believe you may need to use items[i].firstChild.firstChild.nodeValue.

    I got this example: x[i].childNodes[j].firstChild.nodeValue, from quirksmode.


    Author Comment

    WOW, that worked???

    It's funny, cause that just doesn't seem logical, but it works??? Thanks heaps, you've saved me alot of headache!

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Both jQuery and Mootools offer some nice, easy to use scripts. Mootools is best known for their interactive slideshows and jQuery for their menus, but both have many other uses as well.   jQuery is basically a toolkit with many DOM (http://en.wik…
    In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now