DOM

The Document Object Model (DOM) is a cross-platform, language-independent convention, standardized by the W3C, for representing and interacting with the objects that make up an HTML or XML document.

A DOM-based parser reads the entire input and builds a tree representation of the document - the DOM tree - in memory. Building this tree can take considerable time and space, since the full document must be held in memory at once before processing can begin.

Once the tree is loaded, random access is possible in any order: nodes can be revisited, reordered, inserted, or removed freely. This makes DOM well suited to tasks such as document rearrangement, in-place editing, validation, and repeated XPath or XSLT evaluation, where the same document is queried or transformed more than once.

Because the whole document must be materialized before processing begins, DOM is generally less memory-efficient than streaming models such as SAX or StAX, and is less suitable for very large documents or single-pass, low-memory processing.

DOM is implemented by most XML toolkits, including Xerces, MSXML, and libxml2, and is exposed natively in browser JavaScript (see String Loading with DOMParser) and in PHP (see DOM Reference).

Full nameDocument Object Model
Standardized byW3C (DOM Core, Levels 1-4)
Processing modelWhole document loaded into an in-memory tree
Access patternRandom access; read and write
Memory useProportional to document size; can be significant for large documents
Typical usesEditing, rearranging, validating, and repeatedly querying or transforming a document

<?php
$dom = new DOMDocument();
$dom->load('books.xml');

foreach ($dom->getElementsByTagName('book') as $book) {
    $title = $book->getElementsByTagName('title')->item(0)->nodeValue;
    echo $book->getAttribute('id') . ": " . $title . "\n";
}
?>