You are on page 1of 2

Filename: article.xml <?xml version="1.0"?

> <article> <title>Simple XMl</title> <date>Aug 16,2011</date> <author> <firstName>Neil</firstName> <lastName>Gogte</lastName> </author> <summary>XML is pretty easy</summary> <content>Once u have mastered XHTML,XML is easy learned.You must remember that XML is not for displaying information bur for managing information</content> </article> Filename: domexample.html <?xml vesion="1.0"?> <html> <head> <title>A DOM Example</title> </head> <body> <script type="text/javascript"> var xmlDocument= new ActiveXObject("Microsoft.XMLDOM"); xmlDocument.load("article.xml"); var element=xmlDocument.documentElement; document.writeln("<p> Here is the Root node of the document:"+"<strong>"+element.nodeName+"</strong>"+"<br/>The following are its child elements:"+"</p><ul>"); for(var i=0;i<element.childNodes.length;i++) { var curNode=element.childNodes.item(i); document.writeln("<li><strong>"+curNode.nodeName+"</strong></li>"); } document.writeln("</ul>"); var currentNode=element.firstChild; document.writeln("<p>The first child of the root node is:"+"<strong>"+currentNode.nodeName+"</strong>"+"<br/>whose next sibling is:"); var nextSib=currentNode.nextSibling;

document.writeln("<strong>"+nextSib.nodeName+"</strong><br/>Value of <strong>"+nextSib.nodeName+"</strong> element is:"); var value=nextSib.firstChild; document.write("<em>"+value.nodeValue+"</em>"+"<br/>Parent node of<strong>"+nextSib.nodeName+"</strong>is:<strong>"+nextSib.parentNode.nod eName+"</strong>.</p>"); </script> </body> </html>

You might also like