↑
Main Page
DOM creation
After this line is executed, the
oXmlDom
object behaves like any other DOM Document, complete with all
the properties and methods discussed earlier in the book.
When developers first started using this method of XML manipulation, it was problematic because the
user often did not have MSXML installed. Most of the time, developers had to download the library
from Microsoft directly. However, Internet Explorer 5.0 fixed this problem by shipping with MSXML,
thus ensuring anyone using IE 5.0 or higher could make use of this functionality.
DOM creation
With each new version of MSXML, a new version of the XML DOM object was created, each with its
own unique name. The most recent and final version of MSXML is 5.0, meaning that the following XML
DOM implementations now exist:
?
Microsoft.XmlDom (original)
?
MSXML2.DOMDocument
?
MSXML2.DOMDocument.3.0
?
MSXML2.DOMDocument.4.0
?
MSXML2.DOMDocument.5.0
Naturally, you want the most recent version of the XML DOM whenever possible because of improve-
ments in speed and enhanced support for features such as validation. However, if you try to create an
ActiveX object that doesn’t exist on the client machine, IE throws an error and stops all processing. So,
to be sure you are using the correct version of the XML DOM and to avoid any unsightly errors, create a
function that tries each XML DOM string and captures any errors that occur:
function createXMLDOM() {
var arrSignatures = [“MSXML2.DOMDocument.5.0”, “MSXML2.DOMDocument.4.0”,
“MSXML2.DOMDocument.3.0”, “MSXML2.DOMDocument”,
“Microsoft.XmlDom”];
for (var i=0; i < arrSignatures.length; i++) {
try {
var oXmlDom = new ActiveXObject(arrSignatures[i]);
return oXmlDom;
} catch (oError) {
//ignore
}
}
throw new Error(“MSXML is not installed on your system.”);
}
This function contains an array of all the possible XML DOM strings, called
arrSignatures
, sorted in
descending order from most recent to least recent. The
for
loop tries to create an XML DOM object by
446
Chapter 15
18_579088 ch15.qxd 3/28/05 11:42 AM Page 446
Free JavaScript Editor
Ajax Editor
©
→