Objectives
To understand what the Document Object Model is
To understand and be able to use the major DOM features
To use JavaScript to manipulate an XML document
To use Java to manipulate an XML document
To become familiar with DOM-based parsers
Introduction
DOMs are to manipulate the contents of an XML document.
XML documents, when parsed, are represented as a hierarchical tree structure in memory. This tree structure contains the document's elements, attributes, content, etc. XML was designed to be a live, dynamic technology - a programmer can modify the contents of the tree structure, which essentially allows the programmer to add data, remove data, query for data, etc. in a manner similar to a database. The W3C provides a standard recommendation for building a tree structure in memory for XML documents called the XML Document Object Model (DOM). Any parser that adheres to this recommendation is called a DOM-based parser. Each element, attribute, CDATA section, etc., in an XML document is represented by a node in the DOM tree. For example, the simple XML document Hi, Tem!
results in a DOM tree with several nodes. One node is created for the message element. This node has a child node that corresponds to the body element. The body element also has a child node that corresponds to the text Hi, Tem!. The from and to attributes of the message element also have corresponding nodes in the DOM tree.
A DOM-based parser exposes (i.e., makes available) a programmatic library - called the DOM
Application Programming Interface (API) - that allows data in an XML document to be accessed and modified by manipulating the nodes in a DOM tree.
Portability:
The DOM interfaces for creating and manipulating XML documents are platform and language independent. DOM parsers exist for many different languages, including Java,
C, C+ +, Python and Perl.
Another API - JDOM-provides a higher-level API than the W3C DOM for