 | Level: Intermediate Contributors: W3C 06 Feb 2007 Updated 25 Apr 2007 Learn to use the Document Object Model (DOM), a tree
API that provides direct access to parts of an XML document. DOM is
probably the most popular means of accessing XML documents, offering
convenience at the expense of performance.
Document Object
Model (DOM)
[W3C Recommendation] is an object model for XML
documents that you can use to access parts of an XML document directly.
In DOM, the document is modeled as a tree, where each component of the
XML syntax (such as an element or text content) is represented by a
node. DOM is an API that allows you to navigate this tree, moving from
parent to child node, to siblings, and more, taking advantage of special
properties of certain types of nodes (for instance, elements can have
attributes, while text nodes have text data). DOM is designed to be
language-neutral. The Object Management Group's (OMG's)
CORBA Interface
Definition Language (IDL)
[ISO International Standard, number 14750] is used
to express DOM node and support interfaces.
DOM actually originated as an object model for
standardizing scripting operations on HTML and XML objects in Web
browsers. In some places, this translates to awkwardness when it is used
as a standalone programming API, but this is the usage focused on in
this discussion. DOM is evolving through several levels, each of which
builds added capabilities upon the prior one. Level 1 covered the
basics; Level 2 added namespace support, a UI event model, iterators,
and more; and Level 3 adds APIs for loading to and saving from XML
document files, integrating XPath, support for validation, and more.
DOM is generally much easier to master than Simple API
for XML (SAX) because it doesn't involve callbacks and sophisticated
state management. However, DOM implementations generally keep all XML
nodes in memory, which can be inefficient for larger documents. Many
languages have featured DOM implementations, but because DOM tries to be
language-neutral, adherents of particular languages often complain that
it is awkward and doesn't take advantage of any language's particular
strengths. As a result, many language-specific tree APIs have
flourished.
Resources
|  | |  |