XMLHttpRequest Object (2)
Let's use an example to demonstrate a small XML application built with HTML
and Javascript
Look at the following XML document (book_catalog.xml):
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<BOOK>
<TITLE>GIS for Web Developers: Adding 'Where' to Your Web Applications</TITLE>
<AUTHOR>Scott Davis</AUTHOR>
<LINK>http://www.selectagps.com/GIS-for-Web-Developers--d_0974514098.html</LINK>
<PRICE>34.95</PRICE>
</BOOK>
.
.
... more ...
.
To load the XML document (book_catalog.xml):
var xmlDoc;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Firefox, Mozilla, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Error!');
}
xmlDoc.async=false;
xmlDoc.load("book_catalog.xml");
After the execution of this code, xmlDoc is an XML DOM object, accessible by
Javascript.
|