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:

<staff>

    <member>
        <name>Joe Gerilo</name>
        <schedule>Mon-Fri</schedule>
            <office>
                <city>Chiago</city>
                <building>31st AMC</building>
                <boss>John H</boss>
                <duties>Acconuting</duties>
            </office>
            <office>
                <city>NY</city>
                <building>31st AMC</building>
                <boss>Mike R</boss>
                <duties>Acconuting</duties>
            </office>
    </member>

    <member>
        ...
    </member>

</staff>



window.onload = function(){
  var xmlRequest = new XMLHttpRequest();
  xmlRequest.open("GET","class.xml", false);
  xmlRequest.send();
  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!

Thanks

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.