News:

This week IPhone 15 Pro winner is karn
You can be too a winner! Become the top poster of the week and win valuable prizes.  More details are You are not allowed to view links. Register or Login 

Main Menu

Loading an XML File - A Cross browser Example

Started by ben2ong2, October 05, 2006, 05:20:29 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

ben2ong2

The following example is a cross browser example that loads an existing XML document ("note.xml") into the XML parser:
<html><head><script type="text/javascript">var xmlDocfunction loadXML(){//load xml file// code for IEif (window.ActiveXObject)  {  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");  xmlDoc.async=false;  xmlDoc.load("note.xml");  getmessage()  }// code for Mozilla, etc.else if (document.implementation &&document.implementation.createDocument)  {  xmlDoc= document.implementation.createDocument("","",null);  xmlDoc.load("note.xml");  xmlDoc.onload=getmessage  }else  {  alert('Your browser cannot handle this script');  }}function getmessage(){document.getElementById("to").innerHTML=xmlDoc.getElementsByTagName("to")[0].firstChild.nodeValuedocument.getElementById("from").innerHTML=xmlDoc.getElementsByTagName("from")[0].firstChild.nodeValuedocument.getElementById("message").innerHTML=xmlDoc.getElementsByTagName("body")[0].firstChild.nodeValue}</script></head><body onload="loadXML()" bgcolor="yellow"><h1>W3Schools Internal Note</h1><p>To: <span id="to"></span>
From: <span id="from"></span>
Message: <span id="message"></span></p></body></html>
Try it yourself
There are more examples of this in our XML DOM tutorial.

You are not allowed to view links. Register or Login
You are not allowed to view links. Register or Login