Home | All Questions | alt.html FAQ > Client-side Basic Scripting

How do I process XML files with Javascript?

Mozilla based browsers:

 var httpRequest = new XMLHttpRequest();
 httpRequest.open('GET', 'gods.xml', false);
 httpRequest.send(null);
 var xmlDocument = httpRequest.responseXML;
 alert(xmlDocument.documentElement.nodeName)

Internet Explorer (version 5 and above):

 var httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
 httpRequest.open('GET', 'gods.xml', false);
 httpRequest.send();
 var xmlDocument = httpRequest.responseXML;
 alert(xmlDocument.documentElement.nodeName)

You can only connect to the server your script page is loaded from, not any other server

Recommended Resources

Discussion

Related Questions