using the string in position
and assigned it to the variable
. If that version of the XML DOM
isn’t present on the user ’s machine, it causes an error, which is caught by the
ignored. When that error occurs, the line
is completely skipped, and the
again. Only if the XML DOM object is successfully created is it returned as the function value. If, on the
other hand, each version of the XML DOM is tested and no version is available, the function throws its
own error telling the user that MSXML isn’t installed on the system and processing cannot continue.
By using this function, you can be sure that the XML DOM version you are using is the most recent:
var oXmlDom = createXMLDOM();
Now that you have an XML DOM object, you load some XML into it. Microsoft’s XML DOM comes with
two methods for loading XML:
method enables you to enter an XML string directly into the XML DOM:
method is used to load an XML file from the server. Rather, the
method can load an
XML from someone else’s server.
There are two modes of loading a file: synchronous and asynchronous. When you load a file in syn-
code; a file loaded in asynchronous mode won’t wait, so you need to use an event handler to determine
when the file has been fully loaded.
By default, files are loaded asynchronously. To set files to load synchronously, just set the
oXmlDom.async = false;
You can then use the
method by passing in the name of the file to load:
After this line executes,
contains a DOM Document representing the XML file, so you can use
all the DOM properties and methods:
alert(“Tag name of the root element is “ + oXmlDom.documentElement.tagName);
alert(“The root element has this many children: “ +
The code to create an XML DOM in Internet Explorer causes an error in any other
browser. Therefore, you must do a browser detect before attempting to create the
XML DOM in this way.
18_579088 ch15.qxd 3/28/05 11:42 AM Page 447