Reading XML File

I’ve attempted to follow several tutorials but have run into a problem when trying to read an XML file using Javascript. Below is some general information about the problem:

Html file that includes the javascript file is located in root (/).
Javascript file containing all of the javascript seen below is (/js
XML file being called is in /js/views/viewDirectory.xml

var installedViews = createXMLDoc('js/views/viewDirectory.xml');
//alert(installedViews.documentElement.childNodes.length); //Prints '9'
//alert(installedViews.documentElement.tagName); //Prints views
for (var i = 0; i < installedViews.documentElement.childNodes.length; i++){
                var viewsNode =  installedViews.documentElement.childNodes;
                //alert( viewsNode[i].tagName+","+ viewsNode[i].childNodes[1].tagName+","+viewsNode[i].childNodes[1].text); //Prints "View,file,undefined"
                //alert( viewsNode[i].tagName+","+ viewsNode[i].childNodes[0].tagName+","+viewsNode[i].childNodes[0].text); //Prints "View,undefined,undefined"

function createXMLDoc(file)
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    return xmlhttp.responseXML; 

You will notice above I’ve included some alert commands with their output.

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

Above you will see that there are 4 child nodes. But for some reason the script says this are 9. When looping through the alerts fail every other time because every other child is not a real child. This throws an error in firefox.

In IE i’m getting an access is denied error. However, I’ve printed out xmlhttp.responseText in createXMLDoc() and it prints the xml file. So to me it seems to be able to open the document. In addition, when I print xmlhttp.responseXML it states that it is an XML Doc.

Any suggestions on what could be making this simple task so difficult for me?


One small update.

In the loop I changed the updated the alerts as so:

alert( viewNode.tagName+","+ viewNode.childNodes[1].tagName+","+viewNode.childNodes[1].childNodes[0]);
alert( viewNode.tagName+","+ viewNode.childNodes[0].tagName+","+viewNode.childNodes[0].childNodes[0]); 

Now these alerts print the following lines
view,file,[object Text]
view,class,[object Text]

However, if I add a .text or .value on the end like this:

alert( viewNode.tagName+","+ viewNode.childNodes[1].tagName+","+viewNode.childNodes[1].childNodes[0].text);
alert( viewNode.tagName+","+ viewNode.childNodes[0].tagName+","+viewNode.childNodes[0].childNodes[0].value); 

it prints out

To me it seems strange to be able to view that it is a text object but not be able to print the text from the object.