Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Document Object Model (DOM)

Access parsed XML documents as trees of node objects

Contributors:  W3C

Summary:  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.

Date:  25 Apr 2007 (Published 06 Feb 2007)
Level:  Intermediate

Activity:  4363 views
Comments:  

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

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=193468
SummaryTitle=Document Object Model (DOM)
publish-date=04252007

My developerWorks community

IBM SmartCloud trial. No charge.

IBM PureSystems on a kaleideoscope background

Unleash the power of hybrid cloud computing today!