HTML DOM Example 2

Estudies4you
HTML DOM Example
HTML DOM Example 2:
Note_string.html

<html>
<head>
<script type="text/javascript"›
function parseXML()
{
text="<note>";
text=text+"<to>Raju</to>";
text=text+"<from>Ravi</from>";
text=text+"<heading>Reminder</heading>";
text=text+"<body>Don't forget to meet me this weekend!</body>";
text=text+"</note>";
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(text);
} catch(e)
{ try //Firefox, Mozilla, Opera, etc.
{ parser=new DOMParser();
xmlDoc=parser.parseFromString(text,"text/xml");
} catch(e)
{ alert(e.message);
return; }
}
}
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").innerHTML=xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
}

</script>
</head>
<body onload="parseXML()">
<h1>Load and parse an XML string</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>

Output:
HTML DOM Example

To Top