# Read XML file cross browser example

**URL:** <https://forum.kirupa.com/t/read-xml-file-cross-browser-example/271745>\
**Category:** Uncategorized\
**Created:** [September 27, 2008, 5:00pm UTC](https://forum.kirupa.com/t/read-xml-file-cross-browser-example/271745 "2008-09-27T17:00:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![piroshki](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@piroshki](https://forum.kirupa.com/u/piroshki)\
**Post date:** [September 27, 2008, 5:00pm UTC](https://forum.kirupa.com/t/read-xml-file-cross-browser-example/271745/1 "2008-09-27T17:00:59Z")

</div>

Hi again.  
I have been trying to read an xml file using a combination of xmlhttprequest and activeObject to make it work for all browsers. This is my code. I cannot load the xml document at all, it returns no properties. Any idea?

var product = window.opener.message;  
document.title = product;  
var xmlStr = “’”+“xml/” + product + “.xml”+"’";  
alert (xmlStr);  
var browser=navigator.appName;  
function getHTTPObject()  
{  
var xmlhttp;

if (browser==“Microsoft Internet Explorer”)  
try  
{  
xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);  
}  
catch (e)  
{  
try  
{  
xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);  
}  
catch (E)  
{  
xmlhttp = false;  
}  
}  
else  
xmlhttp = false;

```
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
    {
        try
        {
            xmlhttp = new XMLHttpRequest();
        }
        catch (e)
        {
            xmlhttp = false;
        }
    }

    return xmlhttp;

```

}  
var xmlHttp = getHTTPObject();  
function processxmlHttpChange() {  
// only if req shows “loaded”  
if (xmlHttp.readyState == 4) {

```
    if (xmlHttp.status == 200) {
        // ...processing statements go here...
    } else {
        alert("There was a problem retrieving the XML data:

```

" +  
xmlHttp.statusText);  
}  
}  
}

function getDynamicData()  
{  
var url = xmlStr;  
alert(“Hello” + xmlStr);  
xmlHttp.open(‘GET’, url, true);  
xmlHttp.onreadystatechange = processxmlHttpChange;  
xmlHttp.send(null);  
var dom = xmlHttp.responseXML;  
alert(dom.documentElement.nodeName);  
document.getElementById(“name”).innerHTML=dom.getElementsByTagName(“NAME”)[0].childNodes[0].nodeValue;  
document.getElementById(“myPic”).src=dom.getElementsByTagName(“IMAGE”)[0].childNodes[0].nodeValue;  
document.getElementById(“pack”).innerHTML=dom.getElementsByTagName(“PACK”)[0].childNodes[0].nodeValue;  
document.getElementById(“des”).innerHTML=dom.getElementsByTagName(“DES”)[0].childNodes[0].nodeValue;  
document.getElementById(“incr”).innerHTML=dom.getElementsByTagName(“INCR”)[0].childNodes[0].nodeValue;  
document.getElementById(“use”).innerHTML=dom.getElementsByTagName(“USE”)[0].childNodes[0].nodeValue;

}

\<body onload=“getDynamicData();”\> etc etc
