PDA

View Full Version : safari is not able to read xml (using javascript)



sugata_bhar
Mar 10th, 2008, 06:13 AM
Hi All

Please see http://www.w3schools.com/xml/tryit.asp?filename=tryxml_parsertest

This is not working in Safari

Please help

Thanks
Sugata

mjlorbet
Mar 10th, 2008, 09:36 AM
<html>
<head>
<script type="text/javascript">
function parseXML()
{
var XmlHTTP = null;
var Possibles = {0: "XMLHttpRequest()", 1: "ActiveXObject('Microsoft.XMLHttp')", 2:"ActiveXObject('MSXML2.XMLHttp')", 3:"ActiveXObject('MSXML2.XMLHttp.3.0')", 4:"ActiveXObject('MSXML2.XMLHttp.4.0')", 5:"ActiveXObject('MSXML2.XMLHttp.5.0')", 6:"ActiveXObject('MSXML2.XMLHttp.6.0')", 7:""};
var Option = 0;
while(XmlHTTP === null){
XmlHTTP = eval("new " + Possibles[Option]);
}
if(XmlHTTP === null)
return false;
XmlHTTP.open("get", "note.xml", false);
XmlHTTP.send("");
var xDoc = XmlHTTP.responseXML;
document.getElementById("to").innerHTML=xDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=xDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=xDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}
</script>
</head>
<body onload="parseXML()">
<h1>W3Schools Internal Note</h1>
<p><b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</p>
</body>
</html>