What is DOM?
The DOM (Document Object Model) is a W3C standard programming interface for constructing, accessing, and manipulating XML
A DOM is a tree of objects (“nodes”) that expose all the information in an XML document.
DOMs are accessible from a variety of programming languages (i.e., Java, Java Script, Python, C++, and Visual Basic).
- Accelerates development by standardizing the data retrieval interface to a single object model and API.
- Simplifies new program development by reducing the number and types of data access interfaces.
- Eliminates the need to develop application-specific code for parsing and accessing XML.
- Large pool of programmers familiar with DOM programming.
- DOM programming knowledge and skills transferable across applications and programming languages.
- Same application code can be quickly and easily bound to different DOM implementations.
How DOM works:
XML documents are turned into in-memory DOM objects by a DOM implementation , which is a type of XML processor that parses an XML document and creates objects in memory corresponding to the elements, attributes, and data content of the XML document. These objects are called “nodes” in DOM terminology. Each node is an object that implements the DOM API. Application programs operate on DOM nodes to get data from the XML document, create new XML documents from scratch, or modify existing XML documents.
There are many DOM implementations for a wide variety of programming languages. Because all DOM implementations must implement the same API, an application program can use different DOM implementations simply by changing the DOM implementation it uses—none of the DOM processing code needs to change. Many operating platforms now have built-in DOM implementations.
It is also possible for data bases and other data sources to expose their data through a DOM API, XML or not, as though it were XML. This means that DOM-based applications can operate on a variety of data sources with little or no code change and without necessarily requiring that the data in the underlying data source be literally converted to XML. For example, relational database systems like Oracle and Sybase provide DOM APIs for accessing relational databases as though the data in the relational tables had been exported as XML documents.
DOM-based applications represent one of the primary styles of XML processor. The other primary style of XML processor is “event-based” or SAX-based. In DOM-based applications, access to the document content is very convenient for programmers but may require putting entire XML documents into memory, which may be a problem for applications that need to process very large documents. SAX-based applications are less convenient for programmers but, because they almost never require putting an entire document in memory, can process very large documents easily. For certain types of processing, SAX-based processing may be significantly faster than DOM-based processing. Many DOM implementations are themselves SAX-based, essentially converting SAX events into DOM objects.