↑
Main Page
MSXML2.DOMDocument
Document.prototype.__checkForErrors__ = function () {
if (this.documentElement.tagName == “parsererror”) {
var reError = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+), Column
(\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;
reError.test(this.xml);
this.parseError.errorCode = -999999;
this.parseError.reason = RegExp.$1;
this.parseError.url = RegExp.$2;
this.parseError.line = parseInt(RegExp.$3);
this.parseError.linepos = parseInt(RegExp.$4);
this.parseError.srcText = RegExp.$5;
}
};
Note that the
errorCode
is set to
–999999
no matter what error occurs. Trying to map all of Microsoft’s
error codes would be a tedious and unnecessary task. Most of the time, you just check to see if
parseError
is anything other than
0
, not necessarily a particular number.
Next, the
load()
and
loadXML()
methods must be updated to use
initError()
(to clear all error val-
ues before parsing begins) and
checkForErrors()
(to check for any parsing errors when the parsing
has completed):
function XmlDom() {
if (window.ActiveXObject) {
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.”);
} else if (document.implementation && document.implementation.createDocument) {
var oXmlDom = document.implementation.createDocument(“”,””,null);
oXmlDom.parseError = {
valueOf: function () { return this.errorCode; },
461
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 461
Free JavaScript Editor
Ajax Editor
©
→