HTML DOM Example 1

Estudies4you
HTML DOM
HTML DOM Example 1:
Note.html
<html>
<head>
<script type="text/javascript"›
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("",",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDoc.load("note.xml"); document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; document.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue; document.getElementById("message").innerHTMI=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}
 </script>
</head>
<body onload="parseXML()">
<hl>Loading and parsing an XML file</hl>
<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>

Note.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Raju</to>
<from>Ravi</from>
<heading>Reminder</heading>
<body>Don't forget to meet me this weekend! </body>
</note>

OUTPUT:
HTML DOM

To Top