Introduction to XML Document Object Model - DOM Simplified
(Page 3 of 5 )
DOM Simplified
Now let us look at the node structure of our XML document with little more detail. We will examine one side of the document structure alone for ease of explanation. All this applies to the other side as well.

Here in Figure1, you can clearly see how you can use these properties to navigate around the XML DOM. The lines indicate which nodes the properties point to. The children on the root node, BookAuthor, are held in the childNode collection. In the above case BookAuthor only has one child, so both its firstChild and its lastChild properties point to the same node. In the above case which we are discussing, childNode(0 will apply. Since it is the only node in the collection.
The Author node however, has three children, held in a childNodes collection. The pointer to the au_id is that of firstChild property, which is the same as childNodes(0), and the lastchild property points to au_fname node. The previousSibling and nextSibling properties point to the next node collection at the same level.
So let us assume we have a node named baRoot pointing to BookAuthors, the following table helps demonstrate the parent-child hierarchy.
| Code | Points To |
| baRoot.childNodes(0) | Author |
| baRoot.childNodes(0).firstChild | au_id |
| baRoot.childNodes(0).firstChild.nextSibling | au_lname |
| baRoot.childNodes(0).firstChild.parentNode | Author |
| baRoot.childNodes(0).firstChild.nextSibling.parentNode | Author |
Specific DOM Objects
XML, was designed to be eXtensible, data integration and data exchange is one of its key features. XML was anchored to cater to a tremendous variety of documents. Despite this there are no specific objects for different types of node. Really, what makes it so intriguing is that, they inherit most of the properties and methods of the Node objects as well as adding specific methods and properties relevant to the particular node type. The following table lists the specific DOM Objects:
| Object | Description |
| Document | The root object for an XML document. |
| DocumentType | Stores info about DTD or Schema associated with the XML document.[For e.g. !DOCTYPE in a DTD] |
| DocumentFragment | A lightweight copy of the document. Useful for temporary storage or document insertions. |
| Element | An XML element. |
| Attribute or Attr | An XML attribute. |
| Entity | A parsed or unparsed entity.[E.g. !ENTITY in a DTD.] |
| EntityReference | An XML entity reference. |
| Notation | A notation.[e.g.!NOTATION in DTD] |
| CharacterData | The base object for text information in an XML document. |
| CDATASection | Unparsed character data (e.g. !CDATA in DTD) . |
| Text | The text content of an element or attribute node. |
| Comment | An XML comment element. |
| ProcessingInstruction | A processing instruction as held in <? ?> section |
| Implementation | Application specific implementation details.
|
Next: Working With XML Data >>
More XML Articles
More By Gayathri Gokul