responseXML in IE
Hi all,
Please help me out of this quagmire,
I have an application in which i retrieve data from XML file named, data.xml, and display it in TRs in html page, named ajaxexample.html.
It is working fine in Firefox, but seems to have some issues in IE.
The content of html file is as below:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript"><!--
function ajaxRead(file){
var xmlObj = null;
if(window.XMLHttpRequest){
xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject){
xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
return;
}
xmlObj.onreadystatechange = function(){
if(xmlObj.readyState == 4){
processXML(xmlObj.responseXML);
}
}
xmlObj.open ('GET', file, true);
xmlObj.send ('');
}
function processXML(obj){
var dataArray = obj.getElementsByTagName('pet');
var dataArrayLen = dataArray.length;
var insertData = '<table style="width:150px; border: solid 1px #000"><tr><th>'
+ 'Pets</th></tr>';
for (var i=0; i<dataArrayLen; i++){
insertData += '<tr><td>' + dataArray[i].firstChild.data + '</td></tr>';
}
insertData += '</table>';
document.getElementById ('dataArea').innerHTML = insertData;
}
//--></script>
</head>
<body>
<h1>Developing Web Applications with Ajax</h1>
<p>This page particularly demonstrates the retrieval and processing of grouped sets of XML data.
The data retrieved will be output into a tabular format below.
<a href="#" onClick="ajaxRead('data.xml'); return false">See the demonstration</a>.</p>
<div id="dataArea"></div>
</body>
</html>
The content of xml file (data.xml):
<?xml version="1.0" encoding="UTF-8"?>
<data>
<pets>
<pet>Cat</pet>
<pet>Dog</pet>
<pet>Horse</pet>
</pets>
</data>
Please help me out.
Thanks in advance
|