Hey guys,
I'm trying to take xml code and present it to the client via html. Creating the xml file was the easy part, the part I'm having an issue with the javascript code.
Here is the xml code:


        <name>Joe Gerilo</name>
                <building>31st AMC</building>
                <boss>John H</boss>
                <building>31st AMC</building>
                <boss>Mike R</boss>



window.onload = function(){
  var xmlRequest = new XMLHttpRequest();
  xmlRequest.open("GET","class.xml", false);
  var xmlDoc = xmlRequest.responseXML;
  document.getElementById("output").innerHTML = xmlDoc.getElementsByTagName("name")[0];

The Error I get is "Uncaught TypeError: Cannot call method 'getElementsByTagName' of null." The output is to be displayed in the <p> in the HTML file with the id "output".

What's the issue here? My goal is to post the data onto the HTML page listing all the employees, their boses, work sites etc, in a legible fashion.

Any help would be greatly appreciated!


5 Years
Discussion Span
Last Post by pritaeas

That means xmlDoc is invalid, or responseXML is. Apart from that, it may return a string, instead of an XML object. Check with your debugger to see what it contains.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.