↑
Main Page
Error handling
var oXmlDom = new ActiveXObject(arrSignatures[i]);
return oXmlDom;
} catch (oError) {
//ignore
}
}
throw new Error(“MSXML is not installed on your system.”);
} else if (document.implementation && document.implementation.createDocument) {
var oXmlDom = document.implementation.createDocument(“”,””,null);
oXmlDom.addEventListener(“load”, function () {
this.__changeReadyState__(4);
}, false);
return oXmlDom;
} else {
throw new Error(“Your browser doesn’t support an XML DOM object.”);
}
}
Now the Mozilla XML DOM properly supports the
readyState
property (for values of
0
,
1
, and
4
), the
onreadystatechange
event handler, the
loadXML()
method, and the
xml
property. The following
example works in both IE and Mozilla:
var oXmlDom = new XmlDom();
oXmlDom.onreadystatechange = function () {
if (oXmlDom.readyState == 4) {
alert(oXmlDom.xml);
}
};
oXmlDom.load(“test.xml”);
The main difference between the two is how the two XML DOMs handle errors. But this can be remedied.
Error handling
The last step is to create a
parseError
object for Mozilla. Once again, it’s not possible to provide every
IE property, but you have enough information in the Mozilla parser error XML to mimic most of them.
To begin, this object must be created in the
XmlDom
constructor with all its initial values set:
function XmlDom() {
if (window.ActiveXObject) {
var arrSignatures = [“MSXML2.DOMDocument.5.0”, “MSXML2.DOMDocument.4.0”,
“MSXML2.DOMDocument.3.0”, “MSXML2.DOMDocument”,
“Microsoft.XmlDom”];
459
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 459
Free JavaScript Editor
Ajax Editor
©
→