Main Page

XML DOM support in Mozilla

+ oError.errorCode + “\n”
+ “Line: “ + oError.line + “\n”
+ “Line Pos: “ + oError.linepos + “\n”
+ “Reason: “ + oError.reason);
Another option is to throw your own errors:
if (oXmlDom.parseError != 0) {
var oError = oXmlDom.parseError;
throw new Error(oError.reason + “ (at line “ + oError.line
+ “, position “ + oError.linepos + “)”);
Regardless of how you end up representing errors, it’s always best to check the XML DOM for errors
immediately after it’s loaded.
XML DOM support in Mozilla
As with many other things, Mozilla supports a more standard version of the XML DOM than Internet
Explorer. The XML DOM in Mozilla is actually part of its JavaScript implementation, meaning that it
not only evolves with the browser, but it is also readily available on all platforms that Mozilla supports.
Unlike Internet Explorer, which has no XML DOM support on the Macintosh or Unix, Mozilla’s support
crosses all platform boundaries. Additionally, Mozilla’s XML DOM implementation supports DOM
Level 2 functionality, unlike Microsoft’s, which supports only DOM Level 1.
DOM creation
The DOM standard specifies that a method called
be available as part of the
object. Mozilla follows this specification exactly, enabling you to create an XML
DOM like this:
var oXmlDom = document.implementation.createDocument(“”,””, null);
The three arguments for
are the namespace URL for the document, the tag name for
the document element, and a document type object (always
, because no support exists for the doc-
ument type object in Mozilla). The previous line of code creates an empty XML DOM. To create an XML
DOM with a document element, just specify the tag name as the second argument:
var oXmlDom = document.implementation.createDocument(“”,”root”, null);
The MSXML ActiveX controls are available only on Windows; therefore, Internet
Explorer on the Macintosh cannot make use of this functionality. Windows XP
Service Pack 2 introduces new security restrictions on many ActiveX controls, but
MSXML is not one of them (all controls in MSXML are considered to be secure).
Chapter 15
18_579088 ch15.qxd 3/28/05 11:42 AM Page 450

JavaScript EditorFree JavaScript Editor     Ajax Editor