Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

Summary

The Document Object Model was developed to give people writing XML applications common ground on which to build. By creating a series of interfaces representing different node types such as elements and attributes, DOM makes it likely that an application written for one implementation will be able to run in another implementation with only minor changes.

DOM centers around the premise that everything in a document is a Node. A Document is a Node, as is an Element and the Text node that is its child. To add content to an element, you must create a new node and add it using methods such as appendChild() and insertBefore().

Using methods such as getChildNodes() and getElementsByTagName(), you can create a NodeList of nodes and evaluate them one by one.

Attributes are not part of the DOM tree, because they're not considered children of the elements that carry them. Instead, they're properties of the elements. They can be selected as NamedNodeMaps and retrieved by attribute name.

The current version of DOM, Level 2.0, doesn't specify a standard means for loading or saving a Document object, so these functions are left to implementers.

  • + Share This
  • 🔖 Save To Your Account