0

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

2
Contributors
1
Reply
12
Views
4 Years
Discussion Span
Last Post by pritaeas
0

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.