DOM Overview

This article has been excerpted from book "A Programmer's Guide to ADO.NET in C#".
 
Document Object Model 
 
Document object model (DOM) is a platform and language neutral interface that allows programs and scripts to dynamically access and update XML and HTML documents. The DOM API is a set of language independent, implementation neutral interfaces and objects based on the Object Management Group (OMG) Interface Definition Language (IDL) specification (not the COM) version of IDL). Set http://www.w3.org/TR/DOM-Level-2/ for more detail.
 
DOM defines the logical structure of a document's data. You can access the document in a structured format (generally through a tree format). Tree nodes and entities represent the document's data. DOM also helps developers build XML and HTML documents, as well as to add, modify, delete, and navigate the document's data. Figure 6.2 shows you various contents of DOM in a tree structure.
 
 
 
Figure 6.2: DOM tree structure
 
This is the tree structure implementation of an XML file.
  1. <table>  
  2.   <tr>  
  3.     <td>Mahesh </td>  
  4.     <td>Testing</td>  
  5.   </tr>  
  6.   <tr>  
  7.     <td> Second Line</td>  
  8.     <td> Tested</td>  
  9.   </tr>  
  10. </table>  
Figure 6.3 shows the DOM tree representation of this XML.
 
 
 
Figure 6.3. XML DOM tree representation
 
In DOM, a document takes a hierarchical structure, which is similar to a tree structure. The document has a root node, and the rest of the document has branches and leaves.
 
These nodes are defines as interfaces object. You use the interfaces to access and manipulate document objects. The DOM core API also allows you to create and populate documents load documents and save them.
 
Table 6.3 defines some XML document nodes and node contents.
 
Table 6.3: XML Nodes

Node Description Children
Document Represent an HTML or XML document and root of the document tree Element, ProcessingInstruction, DocumentType, Comment
DocumentType Represent the document type attribute of a document No children
Element An element of the document Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference
Attr An attribute Text, EntityReference
ProcessingInstruction
Represent a processing instruction; used in XML No children
Comment Represent comments in an XML or HTML document; characters between the starting <! - - and ending - - > No children
Text Text of a node No children
Entity An entity type item Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference 
 
Conclusion
 
Hope this article would have helped you in understanding DOM. See other articles on the website also for further reference.
 
adobook.jpg This essential guide to Microsoft's ADO.NET overviews C#, then leads you toward deeper understanding of ADO.NET.


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.