Java Reference
In-Depth Information
The order in which they're added is important; you want to always check for the latest version fi rst, so
the version strings are added with the newest at index 0.
Next is a for loop to loop through the elements of the versions array. Inside the loop is a try...
catch statement.
for (var i = 0; i < versions.length; i++)
{
try
{
xmlDoc = new ActiveXObject(versions[i]);
return xmlDoc;
}
catch (error)
{
//do nothing here
}
}
If the ActiveXObject object creation fails in the try block, then code execution drops to the catch
block. Nothing happens at this point: The loop iterates to the next index in versions and attempts to
create another ActiveXObject object with the other MSXML version strings. If every attempt fails,
then the loop exits and returns null. Use the createDocument() function like this:
var xmlDoc = createDocument();
By using this function, you can create the latest MSXML XML DOM object easily.
Before you actually attempt to manipulate the XML fi le, make sure it has completely loaded into the
client's browser cache. Otherwise, you're rolling the dice each time the page is viewed and running the
risk of a JavaScript error being thrown whenever the execution of your script precedes the complete
downloading of the XML fi le in question. Fortunately, there are ways to detect the current download
state of an XML fi le.
The async property denotes whether the browser should wait for the specifi ed XML fi le to fully load
before proceeding with the download of the rest of the page. This property, whose name stands for
asynchronous , is set by default to true, meaning the browser will not wait on the XML fi le before ren-
dering everything else that follows. Setting this property to false instructs the browser to load the fi le
fi rst and then, and only then, to load the rest of the page.
var xmlDoc = createDocument();
xmlDoc.async = false; //Download XML file first, then load rest of page.
xmlDoc.load(“myfile.xml”);
The simplicity of the async property is not without its fl aws. When you set this property to false,
IE will stall the page until it makes contact and has fully received the specifi ed XML fi le. When the
browser is having trouble connecting and/or downloading the fi le, the page is left hanging like a
Search WWH ::




Custom Search