Java Reference
In-Depth Information
for (var i = 0; i < versions.length; i++)
{
try
{
xmlDoc = new ActiveXObject(versions[i]);
return xmlDoc;
}
catch (error)
{
//do nothing here
}
}
}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument(“”,””,null);
return xmlDoc;
}
return null;
}
The code highlighted in gray is the only new code added to the function. It fi rst checks if the
implementation object and implementation.createDocument method exist, and, if so, it creates an
XML DOM for DOM supporting browsers with document.implementation.createDocument() and
returns the DOM object to the caller. Using the function is exactly as you saw earlier, but now it works
across IE, Firefox, and Opera.
var xmlDoc = createDocument();
xmlDoc.async = false;
xmlDoc.load(“myfile.xml”);
Example: Displaying a Daily Message
Now that you know how to load XML documents, let's jump right into building your fi rst XML-enabled
JavaScript application, a message-of-the-day display.
To begin, use the following simple XML fi le. You'll retrieve the fi le and then display the daily message
using DHTML. Following is the XML fi le called motd.xml :
<?xml version=”1.0”?>
<messages>
<daily>Today is Sunday.</daily>
<daily>Today is Monday.</daily>
<daily>Today is Tuesday.</daily>
<daily>Today is Wednesday.</daily>
<daily>Today is Thursday.</daily>
<daily>Today is Friday.</daily>
<daily>Today is Saturday.</daily>
</messages>
Search WWH ::




Custom Search