August 24, 2009

0 Loading an XMl File - A cross browser example

The following example is a cross browser example that loads an existing XML document ("note.xml") into the XML browser

<html>
<head>
<script type="text/javascript">
function LoadXML( )
{
// load xml file
//code for IE

if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject("Mircosoft.XMLDOM")L
xmlDoc.async=false;
xmlDoc.load("note.xml");
getmessage( )

// code for Mozilla, etc

else if (documet.implementation && document.implementation.createDocument("","",null);
xmlDoc.load ("note.xml")
xmlDoc.onload = get message
}
else
{
alert ('Your browser cannot handle this script');
}
}
function getmessage( )
{
document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagNAme("to")[0].firstChild.nodeValue
document.getElementsById("from").innerHTML=
xmlDoc.getElementsById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue
}
</script>
</head>
<body onLoad="loadXML( )" bgcolor="yellow")
<h1>MHIIT Internal Note </h1>
<p><b>To:</b> <span id="from"> </span>
<hr />
<b> Message: </b> <span id="message"> </span>
</p>
</body>
</html>

0 comments:

Post a Comment

Blogger Themes

 
Powered by Blogger