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.
- See the tutorial Understanding DOM by Nicholas Chase (developerWorks, July
2003).
- Perl programmers should see Using
Perl with XML (Part 1), which covers DOM.
- Python programmers should also check out the DOM
page on the standard Python Library Reference.
- ZVON offers nice reference guides, complete with
comprehensive JavaScript™ examples, for DOM Level
1 and DOM
Level 2.
- Read about other XML standards:
Index of XML
standards.
- Participate in any of several XML-centered forums:
XML
zone discussion forums.
- Get involved in the developerWorks community: developerWorks blogs
- Find out how you can become an IBM-Certified
Developer in XML and related technologies at IBM XML
certification.
- See the developerWorks XML Zone for a wide range of
technical articles and tips, tutorials, standards, and IBM Redbooks at
XML
technical library.
- Stay current with technology in these sessions: developerWorks technical events and webcasts.
- Build your next development project with trial
software available for download directly from developerWorks: IBM trial software
