↑
Main Page
initError
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.”);
} else if (document.implementation && document.implementation.createDocument) {
var oXmlDom = document.implementation.createDocument(“”,””,null);
oXmlDom.parseError = {
valueOf: function () { return this.errorCode; },
toString: function () { return this.errorCode.toString() }
};
oXmlDom.__initError__();
oXmlDom.addEventListener(“load”, function () {
this.__changeReadyState__(4);
}, false);
return oXmlDom;
} else {
throw new Error(“Your browser doesn’t support an XML DOM object.”);
}
}
This code uses object literal notation to create the
parseError
object in order to save space. The
valueOf()
method is defined to return the
errorCode
property, which is the same as IE’s implementation; the
toString()
method also returns the
errorCode
property, but as a string primitive. The
initError()
method initializes all the
parseError
object’s properties. Here’s the code:
Document.prototype.__initError__ = function () {
this.parseError.errorCode = 0;
this.parseError.filepos = -1;
this.parseError.line = -1;
this.parseError.linepos = -1;
this.parseError.reason = null;
this.parseError.srcText = null;
this.parseError.url = null;
};
The next step is to check for a parsing error. This must be done in both the
load()
and
loadXML()
meth-
ods because a parsing error can occur in either one. Because it’s bad coding practice to have the same code
in two places, it’s best to create a new method to handle parsing errors:
460
Chapter 15
18_579088 ch15.qxd 3/28/05 11:42 AM Page 460
Free JavaScript Editor
Ajax Editor
©
→