Back
Uncategorized

Document Model Object – A brief introduction

Document Model Object – A brief introduction

Summary

This paper provides the reader with a brief description of the Document Object Model, also known as DOM that is used in the web applications to display and analyze data to enable a better user experience and interaction. The history, use of DOM in parsing objects, and example in using the API methods are also discussed here.

Introduction – DOM, Implementation and Application Programming Interfaces (API)

DOM is a cross platform and language neutral interface standard to interact with objects that are generated in web connections using HTML, XML, XHTML documents. Documents downloaded can be parsed and data can be analyzed by using these objects to further use or store for future use. The predecessor to DOM is JavaScript that is loaded by the web browser in parsing the page and interacting with the data that is loaded through these documents for display or analysis purposes. When different browsers came into existence, a need for standardization arose and hence the DOM specification, the latest being the Draft version 6 released in 2012 [1]. Even though web development led to DOM specification, there are multitudes of other applications that use DOM in passing objects through messages in networks.

Implementation refers to developing inner workings of the objects that are generated. Libraries are provided by specific implementations like, libxml2, Xerces, MSXML, etc. Access of DOM objects in any of these implementations is through Application Programming Interfaces (API). Java community development came up with their JAXP (Java API for XML Processing); JDOM, a Java based package integrates with SAX parsers in building DOM objects; Ajax, is another popular tool that exposes DOM along with other techniques in retrieving data without having to reload the pages.

DOM offers to two levels of interface DOM Core to handle XML documents and DOM HTML, an extension of DOM Core to cover HTML documents in applications.

DOM Objects and Properties – Description and Purpose

1. DOMException object provides a placeholder for exceptions and their descriptions [2]. Its data structure is shown below:

exception DOMException {

unsigned short code;

};

The exception code addresses the type of error generated while parsing the XML document. Some of the errors and constants are provided below:

INDEX_SIZE_ERROR (=1) is generated when the index is negative, or greater than allowed value.

INVALID_STATE_ERR (= 11) is generated when an object that is no longer in existence is called.

SYNTAX_ERR (=12) is generated when an illegal or invalid string is specified.

INVALID_CHARACTER_ERR (=5) when an attempt is made to use an invalid character in the XML document string.

INVALID_MODIFICATION_ERROR (=13) is generated when the type of the object is changed in the application.

The above is a partial list of all the exception codes, which are 17. Access is through static call of the object, like, if(err == DOMException.INVALID_MODIFICATION_ERR).

2. Document object represents the entire HTML or XML document. It is the root of the document tree is a subclass of Node and provides the primary access to the data.

Document object attributes are as follows:

DocumentType doctypeDOMImplementation implementation

Element documentElementThe elements of the document object can be created using the method:

createElement( DOMString tagName). This method uses the XML tag object of type DOMString and raises DOMException when norms are violated.

getElementsByTagName(DOMString tagName) method provides a list of type NodeList, a collection of Element types. The input parameter is the DOMString object. This method does not raise any exception as any invalid input raises DOMString exception.

Conclusion

The explosion of web applications and their adoption by users has led to applications that need to handle data in an elegant and robust manner. The DOM standards were developed by W3C that enabled application developers to express document as data structure. The objects encapsulate the data and allow modification of the content through APIs, two of which are shown above. Further extensions of DOM objects are a certainty with future web applications demand sophistication and handle complexity in a secure manner.

[1].http://www.w3.org/TR/dom[2] http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/

David Lee
David Lee

We use cookies to give you the best experience. Cookie Policy