Tuesday 28 December 2010

Task 8: What is the Document Object Model? Describe its purposes and its use, with examples.


The Document Object Model, or DOM, is an interface to allow programs and scripts to update content, structure, and style of documents dynamically. It is platform- and language-neutral. The DOM is not HTML nor is it JavaScript. It is something like the glue that binds them together. As I have mentioned in other posts about the DOM I iterate again that The DOM is a W3C (World Wide Web Consortium) standard. The DOM defines a standard for accessing documents like XML and HTML. And also it divides into three separated levels. Which were published in the years of 1998, 2000, and 2004 correspondingly.

Core DOM - standard model for any structured document.
XML DOM - standard model for XML documents.
HTML DOM - standard model for HTML documents.

The DOM defines the objects and properties of all document elements, and the methods (interface) to access them.

When you load a document in a Browser, it creates a number of JavaScript Objects with Property values based on the HTML in the document and other pertinent information. These Objects exist in a Hierarchy that reflects the structure of the HTML page itself. The ability to change a Web page dynamically with a scripting language is made possible by the Document Object Model (DOM) which can connect any element on the screen to a JavaScript function. The DOM is the road map through which you can locate any element in your HTML document and use a script, such as JavaScript, to change the element’s properties.


Nodes

Furthermore JavaScript is used to influence XML document. In addition being an object oriented language, JavaScript manipulates  XML document as an  object where properties and methods are as its core feature.  In XML, every part of the document is an element node within the DOM. These nodes come together to form a tree-structure used for navigation by interpreting languages. Since every part of an XML document is a node, the top node is the document itself, known as the ‘documentElement.’ Within the document are smaller nodes that have a relationship with all the connected nodes. This creates the tree hierarchy that interpreters in internet browsers use for navigation. Nodes found within the document element include the root element, child elements, attribute elements, comment elements and text.

What is the Purpose of the XML DOM?

The XML DOM provides a way for browsers with XML parsers to read and manipulate code. By itself, XML does not actually say much. It is a collection of information stored in a file that has no meaning. The DOM structure is what organizes the code so the languages, like JavaScript, can read and understand it. It is the standard model that allows the display of XML data on a web page.


<html>
<head>
<script type="text/javascript" src="loadxmldoc.js">

</script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("hi there.xml");

</script>
</body>
</html>

The file is called "loadxmldoc.js", and will be loaded in the head section of an HTML page. Then, the loadXMLDoc() function can be called from a script in the page. The above code is used to load the xml document (hi there.xml) by using the loadXMLDoc functions.

Reference: Document Object Model DOM ( (2010)[Online] Viewed at : http://docs.python.org/library/xml.dom.html [Accessed 25/12/2010]

No comments:

Post a Comment