<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Champion</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Champion"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Champion"/>
	<updated>2026-06-06T10:12:18Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42233</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42233"/>
		<updated>2010-11-22T22:33:54Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* What is DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser [http://en.wikipedia.org/wiki/Scripting_language Scripting Languages] are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information presented in [http://en.wikipedia.org/wiki/XML XML] and [http://en.wikipedia.org/wiki/Html HTML] documents is in a  structured format. The technique used to access these documents is called Document Object Model (DOM). DOM is platform language independent interface that allows to create and modify the content, structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are an encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to declaration of a set of methods.&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of [http://en.wikipedia.org/wiki/Dynamic_HTML Dynamic HTML], which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript  was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed [http://en.wikipedia.org/wiki/JavaScript JavaScript] and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript:[7] Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMA-262], began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client:[3]  The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server:[3] Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the [http://xerces.apache.org/xerces-c/ Xerces]parser from Apache Foundation.&lt;br /&gt;
* HTML and XML:[1] In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004,[5] Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as [http://en.wikipedia.org/wiki/E4X E4X] (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
'''DOM Core''' :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
'''DOM HTML''' : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes[8]:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element[3], &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property[3],: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in displaying the same chunk of information across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C implementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML HTTP requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline characters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==DOM and SAX==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Simple_API_for_XML SAX] provides a mechanism for reading data from an XML document.&lt;br /&gt;
SAX is a popular alternative to the DOM. However, SAX is not the right tool for this job. Following table differentiates between SAX and DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SAX is sequential'''&lt;br /&gt;
&lt;br /&gt;
SAX does not allow random access to XML document. Only the current element is accessible. Suppose, if the second element is being accessed, then it cannot access information from fourth element because the fourth element hasn't been parsed yet. Also, when the fourth element is getting accessed, it cannot &amp;quot;look back&amp;quot; on the second element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Comparing DOM and SAX'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! DOM&lt;br /&gt;
! SAX&lt;br /&gt;
|-&lt;br /&gt;
| Before processing, stores the entire XML document in memory&lt;br /&gt;
| Sequential and parses node by node&lt;br /&gt;
|-&lt;br /&gt;
| Occupies more memory&lt;br /&gt;
| Doesn't store the XML in memory&lt;br /&gt;
|-&lt;br /&gt;
| We can insert or delete nodes&lt;br /&gt;
| We can't insert or delete a node&lt;br /&gt;
|-&lt;br /&gt;
| Traverse in any direction&lt;br /&gt;
| Top to bottom traversing&lt;br /&gt;
|-&lt;br /&gt;
| Accessing siblings can be done using predefined functions&lt;br /&gt;
| Accessing siblings is difficult due to sequential nature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. It allows the programmer create and modify HTML pages and XML documents as full-fledged program objects&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new &lt;br /&gt;
DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience. XSLT Support has been provided in the latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
# Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/ECMAScript ECMAScript]&lt;br /&gt;
# [https://developer.mozilla.org/En/DOM/Node.attributes Node Attributes]&lt;br /&gt;
# [https://developer.mozilla.org/en/the_dom_and_javascript The DOM and JavaScript]&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-84CF096 Document Object Model Core]&lt;br /&gt;
# [http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html DOM Level 4]&lt;br /&gt;
# [http://www.ecma-international.org/publications/standards/Stnindex.htm ECMAScript Language Specification ]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42232</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42232"/>
		<updated>2010-11-22T22:27:14Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser [http://en.wikipedia.org/wiki/Scripting_language Scripting Languages] are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in [http://en.wikipedia.org/wiki/XML XML] and [http://en.wikipedia.org/wiki/Html HTML] documents is in a  structured format. The technique used to access these document is called Document Object Model (DOM). DOM is platform language independent interface that allows to create and modify the content, structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of [http://en.wikipedia.org/wiki/Dynamic_HTML Dynamic HTML], which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript  was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed [http://en.wikipedia.org/wiki/JavaScript JavaScript] and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript:[7] Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMA-262], began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client:[3]  The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server:[3] Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the [http://xerces.apache.org/xerces-c/ Xerces]parser from Apache Foundation.&lt;br /&gt;
* HTML and XML:[1] In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004,[5] Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as [http://en.wikipedia.org/wiki/E4X E4X] (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
'''DOM Core''' :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
'''DOM HTML''' : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes[8]:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element[3], &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property[3],: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in displaying the same chunk of information across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C implementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML HTTP requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline characters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==DOM and SAX==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Simple_API_for_XML SAX] provides a mechanism for reading data from an XML document.&lt;br /&gt;
SAX is a popular alternative to the DOM. However, SAX is not the right tool for this job. Following table differentiates between SAX and DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SAX is sequential'''&lt;br /&gt;
&lt;br /&gt;
SAX does not allow random access to XML document. Only the current element is accessible. Suppose, if the second element is being accessed, then it cannot access information from fourth element because the fourth element hasn't been parsed yet. Also, when the fourth element is getting accessed, it cannot &amp;quot;look back&amp;quot; on the second element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Comparing DOM and SAX'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! DOM&lt;br /&gt;
! SAX&lt;br /&gt;
|-&lt;br /&gt;
| Before processing, stores the entire XML document in memory&lt;br /&gt;
| Sequential and parses node by node&lt;br /&gt;
|-&lt;br /&gt;
| Occupies more memory&lt;br /&gt;
| Doesn't store the XML in memory&lt;br /&gt;
|-&lt;br /&gt;
| We can insert or delete nodes&lt;br /&gt;
| We can't insert or delete a node&lt;br /&gt;
|-&lt;br /&gt;
| Traverse in any direction&lt;br /&gt;
| Top to bottom traversing&lt;br /&gt;
|-&lt;br /&gt;
| Accessing siblings can be done using predefined functions&lt;br /&gt;
| Accessing siblings is difficult due to sequential nature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. It allows the programmer create and modify HTML pages and XML documents as full-fledged program objects&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new &lt;br /&gt;
DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience. XSLT Support has been provided in the latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
# Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/ECMAScript ECMAScript]&lt;br /&gt;
# [https://developer.mozilla.org/En/DOM/Node.attributes Node Attributes]&lt;br /&gt;
# [https://developer.mozilla.org/en/the_dom_and_javascript The DOM and JavaScript]&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-84CF096 Document Object Model Core]&lt;br /&gt;
# [http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html DOM Level 4]&lt;br /&gt;
# [http://www.ecma-international.org/publications/standards/Stnindex.htm ECMAScript Language Specification ]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42221</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=42221"/>
		<updated>2010-11-22T17:26:23Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* What is DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser [http://en.wikipedia.org/wiki/Scripting_language Scripting Languages] are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in [http://en.wikipedia.org/wiki/XML XML] and [http://en.wikipedia.org/wiki/Html HTML] documents is in a  structured format. The technique used to access these document is called Document Object Model (DOM). DOM is platform language independent interface that allows to create and modify the content, structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of [http://en.wikipedia.org/wiki/Dynamic_HTML Dynamic HTML], which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript  was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed [http://en.wikipedia.org/wiki/JavaScript JavaScript] and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript:[7] Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMA-262], began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client:[3]  The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server:[3] Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the [http://xerces.apache.org/xerces-c/ Xerces]parser from Apache Foundation.&lt;br /&gt;
* HTML and XML:[1] In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004,[5] Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as [http://en.wikipedia.org/wiki/E4X E4X] (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
'''DOM Core''' :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
'''DOM HTML''' : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes[8]:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element[3], &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property[3],: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in displaying the same chunk of information across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C implementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML HTTP requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline characters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==DOM and SAX==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Simple_API_for_XML SAX] provides a mechanism for reading data from an XML document.&lt;br /&gt;
SAX is a popular alternative to the DOM. However, SAX is not the right tool for this job. Following table differentiates between SAX and DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SAX is sequential'''&lt;br /&gt;
&lt;br /&gt;
SAX does not allow random access to XML document. Only the current element is accessible. Suppose, if the second element is being accessed, then it cannot access information from fourth element because the fourth element hasn't been parsed yet. Also, when the fourth element is getting accessed, it cannot &amp;quot;look back&amp;quot; on the second element.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Comparing DOM and SAX'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! DOM&lt;br /&gt;
! SAX&lt;br /&gt;
|-&lt;br /&gt;
| Before processing, stores the entire XML document in memory&lt;br /&gt;
| Sequential and parses node by node&lt;br /&gt;
|-&lt;br /&gt;
| Occupies more memory&lt;br /&gt;
| Doesn't store the XML in memory&lt;br /&gt;
|-&lt;br /&gt;
| We can insert or delete nodes&lt;br /&gt;
| We can't insert or delete a node&lt;br /&gt;
|-&lt;br /&gt;
| Traverse in any direction&lt;br /&gt;
| Top to bottom traversing&lt;br /&gt;
|-&lt;br /&gt;
| Accessing siblings can be done using predefined functions&lt;br /&gt;
| Accessing siblings is difficult due to sequential nature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
# Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/ECMAScript ECMAScript]&lt;br /&gt;
# [https://developer.mozilla.org/En/DOM/Node.attributes Node Attributes]&lt;br /&gt;
# [https://developer.mozilla.org/en/the_dom_and_javascript The DOM and JavaScript]&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-84CF096 Document Object Model Core]&lt;br /&gt;
# [http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html DOM Level 4]&lt;br /&gt;
# [http://www.ecma-international.org/publications/standards/Stnindex.htm ECMAScript Language Specification ]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Domdiff.jpg&amp;diff=41629</id>
		<title>File:Domdiff.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Domdiff.jpg&amp;diff=41629"/>
		<updated>2010-11-17T23:32:02Z</updated>

		<summary type="html">&lt;p&gt;Champion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41628</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41628"/>
		<updated>2010-11-17T23:30:17Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* DOM and SAX */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser [http://en.wikipedia.org/wiki/Scripting_language Scripting Languages] are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in [http://en.wikipedia.org/wiki/XML XML] and [http://en.wikipedia.org/wiki/Html HTML] documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of [http://en.wikipedia.org/wiki/Dynamic_HTML Dynamic HTML], which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript  was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed [http://en.wikipedia.org/wiki/JavaScript JavaScript] and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript:[7] Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, [http://www.ecma-international.org/publications/standards/Ecma-262.htm ECMA-262], began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client:[3]  The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server:[3] Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the [http://xerces.apache.org/xerces-c/ Xerces]parser from Apache Foundation.&lt;br /&gt;
* HTML and XML:[1] In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004,[5] Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as [http://en.wikipedia.org/wiki/E4X E4X] (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
'''DOM Core''' :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
'''DOM HTML''' : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes[8]:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element[3], &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property[3],: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in displaying the same chunk of information across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C implementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML HTTP requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline characters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==DOM and SAX==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Simple_API_for_XML SAX] provides a mechanism for reading data from an XML document.&lt;br /&gt;
SAX is a popular alternative to the DOM. However, SAX is not the right tool for this job. Following table differentiates between SAX and DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''SAX is sequential'''&lt;br /&gt;
&lt;br /&gt;
SAX does not allow random access to XML document. Only the current element is accessible. Suppose, if the second element is being accessed, then it cannot access information from fourth element because the fourth element hasn't been parsed yet. Also, when the fourth element is getting accessed, it cannot &amp;quot;look back&amp;quot; on the second element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domdiff.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
# Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/ECMAScript ECMAScript]&lt;br /&gt;
# [https://developer.mozilla.org/En/DOM/Node.attributes Node Attributes]&lt;br /&gt;
# [https://developer.mozilla.org/en/the_dom_and_javascript The DOM and JavaScript]&lt;br /&gt;
&lt;br /&gt;
==Further Reading==&lt;br /&gt;
# [http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-84CF096 Document Object Model Core]&lt;br /&gt;
# [http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html DOM Level 4]&lt;br /&gt;
# [http://www.ecma-international.org/publications/standards/Stnindex.htm ECMAScript Language Specification ]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41509</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41509"/>
		<updated>2010-11-17T22:37:25Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Browser Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element, &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property,: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in displaying the same chunk of information across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C implementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML HTTP requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline characters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
#  Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41505</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41505"/>
		<updated>2010-11-17T22:36:23Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Levels of DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functions provided include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element, &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property,: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
#  Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41500</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41500"/>
		<updated>2010-11-17T22:35:31Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* History */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification[5], the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript:[6] In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element, &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property,: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;br /&gt;
# Jeremy Keith (2005), ''DOM scripting: Web Design with JavaScript and the Document Object Model'', ISBN: 1-59059-533-5.&lt;br /&gt;
# Joe Marini (2002), ''The Document Object Model: Processing Structured Documents'', ISBN: 0-07-222436-3.&lt;br /&gt;
# [http://www.w3.org/DOM/ Document Object Model (DOM)]&lt;br /&gt;
# Philippe Le Hégaret, [http://www.w3.org/2002/07/26-dom-article.html The W3C Document Object Model]&lt;br /&gt;
#  Stephen Chapman, [http://javascript.about.com/od/reference/a/history.htm A Brief History of Javascript]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41496</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41496"/>
		<updated>2010-11-17T22:35:06Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describe any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logical relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element, &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property,: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;br /&gt;
# Jeffrey Sambells, Aaron Gustafson (2007), ''Advanced DOM scripting: Dynamic Web Design Techniques'', ISBN: 1-59059-856-3.&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41466</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41466"/>
		<updated>2010-11-17T22:18:44Z</updated>

		<summary type="html">&lt;p&gt;Champion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;amp;lt;BODY&amp;amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;amp;lt;B&amp;amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;amp;lt;!-- commented text --&amp;amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
'''Node name, values, types'''&lt;br /&gt;
The above table gives a brief idea about different types of node names, their values and a short description about nodes.&lt;br /&gt;
&lt;br /&gt;
'''Node parents, children, siblings'''&lt;br /&gt;
&lt;br /&gt;
To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNodes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
*parentNode: references a single direct parent of the specific node.&lt;br /&gt;
*childNodes: references all child elements of a node.&lt;br /&gt;
*firstChild: references first child in child nodes.&lt;br /&gt;
*lastChild: references last child in child nodes.&lt;br /&gt;
*previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
*nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
'''Node Attributes'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
&lt;br /&gt;
Accessing Node Attributes:&lt;br /&gt;
 x=element.attributeName                    &lt;br /&gt;
if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
 x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
 x = element.attributes[indexNumber].value    &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
 x= element.getAttribute('attributeName')   &lt;br /&gt;
if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Node OwnerDocument Property'''&lt;br /&gt;
&lt;br /&gt;
This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
*getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
*setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
*removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
*getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
*setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
*removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Element objects within Element objects:&lt;br /&gt;
*The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements,attributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
The document.documentElement property is a shortcut to the root element of the document. &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Creating nodes with document methods&lt;br /&gt;
*createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
*createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
*crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
*createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Locating Elements with Document methods:&lt;br /&gt;
*The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
*The getElementsByTagName('TAG') method: Returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
*The importNode() method: Imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
The diagram below shows DOM representation of a HTML page. The examples below are some of the ways in which elements can be accessed/modified using DOM.&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To list all the nodes that are children of the body element, &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('List child nodes of the document body')&lt;br /&gt;
    for( var i=0 ; i&amp;lt; document..body.childNodes.length ; i++)  {&lt;br /&gt;
        ADS.log.write(document.body.childNodes.item(i).nodeName);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
To elements of 'ListItem' can be accessed using anchor's attributes property,: &lt;br /&gt;
  ADS.addEvent(window, 'load', function() {&lt;br /&gt;
    ADS.log.header('Attributes')&lt;br /&gt;
    var anchor = document.getElementById('ListItem');&lt;br /&gt;
    for( var i=0 ; i&amp;lt; anchor.attributes.length; i++)  {&lt;br /&gt;
        ADS.log.write(anchor.attributes.item(i) + '=' + anchor.attributes.item(i).nodeValue);&lt;br /&gt;
    }&lt;br /&gt;
 });&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41378</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41378"/>
		<updated>2010-11-17T21:28:07Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
When the initial version of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evolution of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for navigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not tied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this are the various parsing libraries &lt;br /&gt;
which can be included int your application for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41376</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41376"/>
		<updated>2010-11-17T21:27:51Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Example DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41373</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41373"/>
		<updated>2010-11-17T21:26:53Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Example DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in Figure 1 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
====Core Node Object====&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure 1 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
! nodeName&lt;br /&gt;
! nodeValue&lt;br /&gt;
! attributes&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure 1, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
| Tag name&lt;br /&gt;
| null&lt;br /&gt;
| NamedNodeMap&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
| Attribute name&lt;br /&gt;
| Attribute value&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure 1, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
| #text&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
| Represents a Character Data selection in an XML document&lt;br /&gt;
| #cdata-section&lt;br /&gt;
| CDATASection content&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
| #comment&lt;br /&gt;
| Comment text&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
| #document&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
| Name of document type&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
| #document-fragment&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
| Target name&lt;br /&gt;
| Content excluding the target&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
| Entity name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
| Name of referenced entity&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
| Notation name&lt;br /&gt;
| null&lt;br /&gt;
| null&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
====Core Element Object====&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
====Core Document Object====&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the intitial versio of DOM specifications were drafted the focus was on the supporting web browsers efficiently. &lt;br /&gt;
However, the evotion of the Web and the widespread use of XML has forced the use of DOM in other application as well. &lt;br /&gt;
For example every application stores some amount of data on either the server or client side when it runs on the internet. &lt;br /&gt;
This information is stored in a structured format and DOM techniques can be used for naigating through these objects. As a result, &lt;br /&gt;
DOM finds wide applications in client-server type of business setups.&lt;br /&gt;
&lt;br /&gt;
Standalone DOM implementations are not ied to larger applications such as web browsers. Instead they are provided as libraries which  &lt;br /&gt;
your applications can use for extracting data from the structured information. Example of this sre the various parsing libraries &lt;br /&gt;
which can be included int your appliation for customized parsing of documents. On the other hand, Embedded DOM implementations are tied&lt;br /&gt;
to larger applications. In these type f applications, DOM is exposed to extensions, such as Macromedia’s Dreamweaver HTML&lt;br /&gt;
authoring applications.&lt;br /&gt;
&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41332</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41332"/>
		<updated>2010-11-17T21:03:58Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;HTML&amp;gt;&lt;br /&gt;
    &amp;lt;HEAD&amp;gt;&lt;br /&gt;
       &amp;lt;TITLE&amp;gt; This document is used as DOM example. &amp;lt;/TITLE&amp;gt;&lt;br /&gt;
    &amp;lt;BODY&amp;gt;&lt;br /&gt;
        &amp;amp;lt;B&amp;amp;gt;Bold text.&amp;amp;lt;/B&amp;amp;gt;&lt;br /&gt;
        &amp;amp;lt;I&amp;amp;gt;Italicized text.&amp;amp;lt;/I&amp;amp;gt;&lt;br /&gt;
    &amp;lt;/BODY&amp;gt;&lt;br /&gt;
 &amp;lt;/HTML&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
DOM is changing the way we browse web pages everyday. As newer version of DOM are drafted to support the modern web standards, it provides better interactivity with web pages. DOM4 promises for developing richer, standardized applications. Also with the advent of new DOM features, the browsers will also see a change in the implementation as well as operation giving the end users a better browsing experience.&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41316</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41316"/>
		<updated>2010-11-17T20:54:00Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Future DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
Following example shows a simple HTML page and corresponding DOM.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;HTML&amp;gt;&lt;br /&gt;
    &amp;lt;HEAD&amp;gt;&lt;br /&gt;
       &amp;lt;TITLE&amp;gt; This document is used as DOM example. &amp;lt;/TITLE&amp;gt;&lt;br /&gt;
    &amp;lt;BODY&amp;gt;&lt;br /&gt;
        &amp;amp;lt;B&amp;amp;gt;Bold text.&amp;amp;lt;/B&amp;amp;gt;&lt;br /&gt;
        &amp;amp;lt;I&amp;amp;gt;Italicized text.&amp;amp;lt;/I&amp;amp;gt;&lt;br /&gt;
    &amp;lt;/BODY&amp;gt;&lt;br /&gt;
 &amp;lt;/HTML&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
&lt;br /&gt;
XSLT Support has been provided in the  latest version of DOM drafted. the initial draft of DOM level 4 was finalized in 2009. DOM4 build on DOM Core Level 3 and also incorporates features from DOM Leve2 HTML.&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41306</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41306"/>
		<updated>2010-11-17T20:49:16Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types. Another feature of Level3 DOM is error handling interfaces.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41304</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41304"/>
		<updated>2010-11-17T20:47:51Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
This level focused on the functionality left out in Level 2 such as Load and Save, etc. Also, support for XPath provides easier navigation through the document. DOM Level 3 introduced two new data types. &lt;br /&gt;
1) DOMObject :  Represents an arbitrary memory object&lt;br /&gt;
2) DOMUserData : Represents an interface to an arbitrary block of data in a DOM application.&lt;br /&gt;
It includes abstract schema modules which support Document Type Definition (DTD) files, XML&lt;br /&gt;
Schemas, and other nonspecific schema types.&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
There are certain types of document processing algorithms that you can use to traverse DOM nodes. These algorithms help to&lt;br /&gt;
* Determine whether a node is contained within another node&lt;br /&gt;
* Determine whether a node has a sibling of a certain type&lt;br /&gt;
*  Finding a node based on the value of an attribute&lt;br /&gt;
* Processing the children of a node&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are two main types of DOM algorithms: position based and content based.&lt;br /&gt;
&lt;br /&gt;
'''Position based '''&lt;br /&gt;
&lt;br /&gt;
Position based DOM algorithms are best when you are more interested in position of nodes within a document than concerned with contents of nodes. For example, to determine whether a node occupies particular place in DOM tree is an application o f position based algorithm.&lt;br /&gt;
&lt;br /&gt;
These algorithms work by examining the locations of nodes within a given DOM document. The contents of the node are secondary (if considered at all). Two common position-based algorithms are &lt;br /&gt;
* Determining whether a node has an ancestor node of a particular type&lt;br /&gt;
* Determining whether a node has a sibling of particular type.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Content-Based Algorithms'''&lt;br /&gt;
&lt;br /&gt;
Content-based algorithms focus on the actual content of the nodes and their attributes. Common content-based algorithms are determining whether a given node contains another particular node, retrieving nodes based upon their type and finding a node with a particular attribute value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41295</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41295"/>
		<updated>2010-11-17T20:40:09Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
This level added support for more types of document operations and content,&lt;br /&gt;
such as events and styles. As result of this, developers had standard ways to handle user events&lt;br /&gt;
and also work with Cascading Style Sheets (CSS) information in the documents.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41293</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41293"/>
		<updated>2010-11-17T20:38:14Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Level allowed basic document operations, such as creating&lt;br /&gt;
and deleting nodes, working with their contents, and traversing the document tree. &lt;br /&gt;
Rest of the operations such as loading and saving documents, etc were left to the developer&lt;br /&gt;
community. So a lot of this code was implementation dependent.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41290</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41290"/>
		<updated>2010-11-17T20:34:53Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Browser Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
DOM plays an important role in dispalying the same chunk ofinfpormation across multiple browsers. AS a result of this&lt;br /&gt;
the user is able to see the same information in Internet Explorer, Firefox, Opera, etc.&lt;br /&gt;
In addition to the standard W3C impementation of DOM, each browser has some proprietary methods and &lt;br /&gt;
properties. This is the primary reason why the browsers differ in their functionality and implementation.&lt;br /&gt;
Internet Explorer supports ActiveXObject for handling XML Http requests while other browsers support the&lt;br /&gt;
MxlHttpRequest object. Another example of the differences might be that some versions prior ti IE6 do not support createAttribute(),&lt;br /&gt;
getAttributeNode(), or setAttributeNode() methods. An alternative to these is to use the getAttribute() &lt;br /&gt;
and setAttribute() methods. NetScape Navigator stores newline charachters as individual text nodes. The developer&lt;br /&gt;
has to take into account these changes while target the web page across multiple browser platforms.&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41266</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41266"/>
		<updated>2010-11-17T20:02:01Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of a web page. The technique used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41263</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41263"/>
		<updated>2010-11-17T19:59:53Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of awe b page. The techniques used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41261</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41261"/>
		<updated>2010-11-17T19:59:36Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
&lt;br /&gt;
   Browser Scripting Languages are widely used today, one example of which is JavaScript.. It allows the user to interact with the web page by accessing the component parts of awe b page. The techniques used to access these components is called Document Object Model (DOM). It creates objects corresponding to the components of the web page which scripting languages interact with to manipulate web pages. &lt;br /&gt;
 &lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41251</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41251"/>
		<updated>2010-11-17T19:52:25Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41247</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41247"/>
		<updated>2010-11-17T19:52:11Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Suggested Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object - http://www.w3.org/DOM/&lt;br /&gt;
2)&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41239</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41239"/>
		<updated>2010-11-17T19:49:45Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* References / External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
1) W3C Document Object [http://www.w3.org/DOM/]&lt;br /&gt;
2)&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41230</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41230"/>
		<updated>2010-11-17T19:46:31Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
This level was drafted in 2003 and 2004. It consists of five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided of this include &lt;br /&gt;
1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
2) serialize your DOM document into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the DOCTYPE.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41228</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41228"/>
		<updated>2010-11-17T19:44:39Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
This level of DOM provides additional interfaces to the existing set of functionality of DOM1. It was first proposed in 2000 and the HTML specification was updated in 2003. It has six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds name-space specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,canceling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41227</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41227"/>
		<updated>2010-11-17T19:42:39Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published in 1998 and later updated in 2000&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41226</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41226"/>
		<updated>2010-11-17T19:40:55Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* What is DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that allows to create and modify the content,structure and style of documents. These changes can be incorporated in the document again. DOM is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published &lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41225</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41225"/>
		<updated>2010-11-17T19:39:46Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
This was the first version of standards published &lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41224</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41224"/>
		<updated>2010-11-17T19:39:36Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Levels of DOM */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
Dom has 3 levels  each with its own specifications. Generally, developers prefer to use DOM Level2 because of its wide support by Internet Explorer (IE) and Firefox. Here is a brief description of each of these levels.&lt;br /&gt;
&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
 This was the first version of standards published &lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41214</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41214"/>
		<updated>2010-11-17T19:27:03Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41212</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41212"/>
		<updated>2010-11-17T19:26:53Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
 a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
 b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41211</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41211"/>
		<updated>2010-11-17T19:26:36Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
   a) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
   b) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41181</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41181"/>
		<updated>2010-11-17T18:31:21Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM2Core''' : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
'''DOM2 HTML''' : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Events''' : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
'''DOM2 STYLE''' : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
'''DOM2 Traversal and Range''' : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
'''DOM2 VIEWS''' : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
   1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
   2) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41180</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41180"/>
		<updated>2010-11-17T18:30:39Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
DOM2Core : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
DOM2HTML : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
DOM2 Events : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
DOM2STYLE : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
DOM2 Traversal and Range : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
DOM2 VIEWS : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Core''' : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Load  and Save''' :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
   1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
   2) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Validation''' : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 Events''' : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
'''DOM3 XPATH''' : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41179</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41179"/>
		<updated>2010-11-17T18:29:51Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
DOM2Core : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
DOM2HTML : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
DOM2 Events : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
DOM2STYLE : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
DOM2 Traversal and Range : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
DOM2 VIEWS : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
Five different specifications&lt;br /&gt;
&lt;br /&gt;
DOM3 Core : Adds more methods and changes to existing core&lt;br /&gt;
&lt;br /&gt;
DOM3 Load  and Save :  Two major functionalities provided are :&lt;br /&gt;
&lt;br /&gt;
     1) content of an XML document can be loaded into your DOM document&lt;br /&gt;
&lt;br /&gt;
     2) serialize your DOM documnet into an XML document&lt;br /&gt;
&lt;br /&gt;
DOM3 Validation : check id dynamic document is valid and conforms to the doctype.&lt;br /&gt;
&lt;br /&gt;
DOM3 Events : handles keyboard and mouse related events.&lt;br /&gt;
&lt;br /&gt;
DOM3 XPATH : Using XPath features to traverse the document&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41178</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41178"/>
		<updated>2010-11-17T18:29:21Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
&lt;br /&gt;
Six different specifications&lt;br /&gt;
&lt;br /&gt;
DOM2Core : Adds namespace specific methods to DOM Core and gives control of structure of DOM elements&lt;br /&gt;
&lt;br /&gt;
DOM2HTML : Similar to DOM HTML&lt;br /&gt;
&lt;br /&gt;
DOM2 Events : Control of mouse related events such as targeting, capturing,cancelling. This does not handle keyboard-related events&lt;br /&gt;
&lt;br /&gt;
DOM2STYLE : Gives access to CSS related styling and rules. Also known as DOM2 CSS&lt;br /&gt;
&lt;br /&gt;
DOM2 Traversal and Range : Iterative access to DOM so that navigating and manipulating the document is easy.&lt;br /&gt;
&lt;br /&gt;
DOM2 VIEWS : Ability to access and update a representation of a document.&lt;br /&gt;
&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41177</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41177"/>
		<updated>2010-11-17T18:28:39Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Level 1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
&lt;br /&gt;
First version of standards published&lt;br /&gt;
&lt;br /&gt;
Consists of two major parts .&lt;br /&gt;
&lt;br /&gt;
DOM Core :  Deals with the internal structure of the nodes of the tree. Also provides, properties and methods to create, edit and manipulate the tree.&lt;br /&gt;
&lt;br /&gt;
DOM HTML : Objects, properties and methods for specific elements associated with HTML documents and tags.&lt;br /&gt;
&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41176</id>
		<title>CSC/ECE 517 Fall 2010/ch6 6g ss</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch6_6g_ss&amp;diff=41176"/>
		<updated>2010-11-17T18:27:50Z</updated>

		<summary type="html">&lt;p&gt;Champion: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;p style=&amp;quot;font-size:25px&amp;quot;&amp;gt;  &amp;lt;b&amp;gt;	Document Object Model &amp;lt;/b&amp;gt; &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
===What is DOM===&lt;br /&gt;
Information is presented in XML and HTML documents is in a  structured format. The technique used to access these document si called Document Object Model (DOM). Dom is platform language independent interface that alows to create and modify the content,structure and style of documents. It is based on the O-O concepts :&lt;br /&gt;
&lt;br /&gt;
Objects are the main part while representing these objects. We can say that Objects are encapsulation of a set of methods and interfaces. Methods are used to access or change the object’s state and interfaces refer to  declaration of a set of methods&lt;br /&gt;
&lt;br /&gt;
===What DOM isn't===&lt;br /&gt;
1) It does not describe how to persist objects into XML or HTML, but it represents documents as a collection of objects.&lt;br /&gt;
&lt;br /&gt;
2) DOM does not describt any internal representation of object or data. It is not a specific set of data structures. For example, even though we have parent-child relationship between the nodes they are logocal relationships of objects.&lt;br /&gt;
&lt;br /&gt;
3) In addition, DOM does not describe what information in a document is relevant or how that information in structured. The structuring of the document is stored by the XML Infoset. DOM is just an API for to access this information.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
* Before DOM became an official W3C specification, the web community the web community had started to develop ways of creating page-based script programs. This early work led to development of Dynamic HTML &amp;lt;refer this&amp;gt;, which was primarily used for richer user interfaces than plain HTML.&lt;br /&gt;
*LiveScript: At the time, Netscape Navigator  was a very popular browser, and also was the first to bring out a programming language that would allow web pages to become interactive. The language, called LiveScript &amp;lt;refer&amp;gt; was  designed at Netscape Communications and came integrated into the Netscape Navigator  browser.&lt;br /&gt;
*JavaScript: In December 1995, LiveScript was renamed JavaScript and released as part of Netscape Navigator 2.0. &lt;br /&gt;
*Jscript &amp;amp; vbscript :  Internet Explorer was updated to support two integrated languages, vbscript and Jscript. Jscript was very similar to JavaScript. In July 1996, Microsoft released Internet Explorer 3.0 supporting these languages.&lt;br /&gt;
*ECMAScript: Netscape delivered JavaScript to Ecma International for standardization and the work on the specification, ECMA-262, began in November 1996.&lt;br /&gt;
*In June 1997, ECMA adopted a hybrid version of the scripting languages called ECMAScript. However, ECMAScript arrived late for the 4.0 releases of Netscape Navigator and Internet Explorer. Each introduced their own document object model, DHTML and dHTML, that came to be called Dynamic HTML.&lt;br /&gt;
*DOM: At the beginning of 1997, the companies involved in this consortium (including Netscape Communications and Microsoft) decided to find a consensus around their object models to access and manipulate documents. While trying to stay as backward compatible as possible with the original browser object models, the W3C's Document Object Model (DOM) provided a better object representation of HTML documents.&lt;br /&gt;
*DOM on Client: &amp;lt;textbook&amp;gt; The Internet Explorer 6 and Netscape Navigator 6 browsers have achieved complete support for DOM Level 1. Other browser vendors followed them.&lt;br /&gt;
*DOM on Server: Soon did the companies realized that the benefits of DOM can be applied on server side as well as client side. DOM implementations began appearing for server-side products as well. One well-known is the Xerces &amp;lt;http://xerces.apache.org/xerces-c/&amp;gt;parser from Apache Foundation.&lt;br /&gt;
* HTML and XML: In 1996, a new markup language, the Extensible Markup Language (XML), was developed in the W3C as well. Meant to remove the HTML language's extensibility restrictions, the idea of developing an object model for XML quickly became another goal of the DOM effort.&lt;br /&gt;
*In June 2004, Ecma International published ECMA-357 standard, defining an extension to ECMAScript, known as E4X (ECMAScript for XML).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Levels of DOM==&lt;br /&gt;
===Level 1 ===&lt;br /&gt;
===Level 2 ===&lt;br /&gt;
===Level 3 ===&lt;br /&gt;
&lt;br /&gt;
==Navigation==&lt;br /&gt;
(I will format this afterwards.. there is a table of around 20 lines to be added)&lt;br /&gt;
DOM represents a document using a tree structure. This tree can be thought as a collection of individual  sub trees. &lt;br /&gt;
image here&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample.jpg]]&lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Figure &amp;lt;x&amp;gt;.1 shows sample HTML document. Figure &amp;lt;x&amp;gt;.2 shows its Document tree diagram.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;BODY&amp;gt; branch can be thought as its own tree within the larger document tree. Each box in &amp;lt;X&amp;gt;.2 is called a node in DOM terminology. The DOM API provides several interfaces in the Core module for manipulating nodes and inserting/extracting information to and from nodes. There are also methods present for determining and changing the relationships between nodes and discovering the type of a particular mode. Lets first have a look at different object types supported by DOM.&lt;br /&gt;
&lt;br /&gt;
''' DOM Core Node Object'''&lt;br /&gt;
A node is an object representation of a particular element in the document's context. Nodes have special names, depending on where they are located in the document tree and what their position is relative to  other nodes.&lt;br /&gt;
&lt;br /&gt;
All documents have a root node.&lt;br /&gt;
&lt;br /&gt;
Each element in Figure &amp;lt;X&amp;gt;.2 extends from Node object. There are few properties of Node object which are available to all DOM objects are extended from Node object.&lt;br /&gt;
&lt;br /&gt;
'''Types of Node Objects'''&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;width: 900px; margin-left:60px; border-style:solid;border:thin;border-spacing:0x;&amp;quot;&lt;br /&gt;
|- style=&amp;quot;text-align: center;border-style:solid;border:thin;border-spacing:0x; &amp;quot;&lt;br /&gt;
! Node Type&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| Element&lt;br /&gt;
| Represents an element in an HTML or XML document, which is represented by tags. In Figure &amp;lt;X&amp;gt;.2, &amp;lt;BODY&amp;gt; node is an element type&lt;br /&gt;
|-&lt;br /&gt;
| Attribute&lt;br /&gt;
| Represents an element's attribute. A tag with the syntax &amp;lt;img src = &amp;quot;picture.jpg&amp;quot;&amp;gt; has an Attribute node src.&lt;br /&gt;
|-&lt;br /&gt;
| Text&lt;br /&gt;
| Represents the textual content of an element. In Figure &amp;lt;X&amp;gt;.2, the &amp;lt;B&amp;gt; node has text child node which represents the text &amp;quot;Bold Text&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| CDATA Selection&lt;br /&gt;
|Represents a Character Data selection in an XML document&lt;br /&gt;
|-&lt;br /&gt;
| Comment&lt;br /&gt;
| Represents a comment. Comments are of the form &amp;lt;!-- commented text --&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Document&lt;br /&gt;
| Represents the root node of a document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentType&lt;br /&gt;
| Each Document node has  a DocumentType node that provides a list of entities defined in the document&lt;br /&gt;
|-&lt;br /&gt;
| DocumentFragment&lt;br /&gt;
| They are lightweight or minimal Document nodes. They help when we want to extract just a portion of a document for processing&lt;br /&gt;
|-&lt;br /&gt;
| ProcessingInstruction&lt;br /&gt;
| Represents instructions to be used by the document processor&lt;br /&gt;
|-&lt;br /&gt;
| Entity&lt;br /&gt;
| Represents an entity in XML document&lt;br /&gt;
|-&lt;br /&gt;
| EntityReference&lt;br /&gt;
| Represents an entity reference in the document&lt;br /&gt;
|-&lt;br /&gt;
| Notation&lt;br /&gt;
| Represents a notation in an XML document. Notations have no parent nodes&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
	- Node name, values, types&lt;br /&gt;
	- Node parents, children, siblings&lt;br /&gt;
	To easily navigate the document tree, each Node object has number of predefined properties that reference various parts of the tree. Each of these properties references an actual DOM object, with exception of childNOdes which references a NodeList of DOM objects (like an array).&lt;br /&gt;
	parentNode: references a single direct parent of the specific node.&lt;br /&gt;
	childNodes: references all child elements of a node.&lt;br /&gt;
	firstChild: references first child in child nodes.&lt;br /&gt;
	lastChild: references last child in child nodes.&lt;br /&gt;
	previousSiblings: Represents sibling node immediately before the selected node.&lt;br /&gt;
	nextSiblings: Represents sibling node immediately after the selected node.&lt;br /&gt;
	&lt;br /&gt;
	- Node Attributes &amp;lt;https://developer.mozilla.org/En/DOM/Node.attributes&amp;gt;&lt;br /&gt;
	Just like rest of DOM document, attributes are also based on the Node object, but they are not part of the general parent/child relationship tree. Attributes are instances of Attr pbject are contained in a NamedNodeMap in node's attributes property. &lt;br /&gt;
	Accessing Node Attributes:&lt;br /&gt;
	&lt;br /&gt;
	x=element.attributeName                    &lt;br /&gt;
	if attributeName is a W3C defined attribute and an Attribute Node for the element, (eg id)  x gets assigned the value of that Attribute Node&lt;br /&gt;
if attributeName isn't a W3C defined attribute or an attribute node for the element, x gets assigned the value of the attributeName property for element (JavaScript object)&lt;br /&gt;
&lt;br /&gt;
	x=element.attributes.attributeName.value   or  x= element.attributes['attributeName'].value&lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
&lt;br /&gt;
	x = element.attributes[indexNumber].value    &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned that node's value. If attributeName isn't an Attribute Node, produce EXCEPTION&lt;br /&gt;
	&lt;br /&gt;
	x= element.getAttribute('attributeName')   &lt;br /&gt;
	if attributeName is an Attribute Node for the element, x gets assigned its value. If AttributeName isn't an Attribute Node for the element, x gets assigned the null value&lt;br /&gt;
&lt;br /&gt;
	- Node OwnerDocument Property&lt;br /&gt;
	This property can be used to reference the root document to which a node belongs.&lt;br /&gt;
&lt;br /&gt;
'''Core Element Object'''&lt;br /&gt;
	Elements inherit from Node object. All element objects have properties and methods of the Node object as well as a few others that facilitate manipulating the attributes of node and locating child element objects.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating 'attributes' property of base node:&lt;br /&gt;
	getAttribute(name) allows to retrieve an attribute based on the name of the attribute as a string.&lt;br /&gt;
	setAttribute(name, value) allows you to set the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	removeAttribute(name) allows to remove the value of an attribute based on the name of the attribute as a string.&lt;br /&gt;
	&lt;br /&gt;
	Methods for manipulating attributes bsed on actual DOM Attr node object:&lt;br /&gt;
	getAttributeNode(name): Allows to retrieve the Attr node of the specified attribute.&lt;br /&gt;
	setAttributeNode(newAttr): Allows to set attributes based on new instances of the Attr object&lt;br /&gt;
	removeAttributeNode(oldAttr): Allows to remove the attribute node the same way one can remove a child node using removeChild() method.&lt;br /&gt;
	&lt;br /&gt;
	Locating Element objects within Element objects:&lt;br /&gt;
	The getElementByTagName() method returns the NodeList object referencing all ancestors with the given tag name.The resulting list is the list of all the elements in the order they appear in DOM Document if read left to right and top to bottom.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Core Document Object'''&lt;br /&gt;
	The Document interface represents the entire document. IT serves as the primary gateway to accessing the document's data. It represents root of the document tree. It also contains methods necessary for creating new document objects such as elements, sattributes, Text nodes, comments. &lt;br /&gt;
	&lt;br /&gt;
	The document.documentElement property&lt;br /&gt;
	It is a shortcut to the root element fo the document. &lt;br /&gt;
	&lt;br /&gt;
	Creating nodes with document methods&lt;br /&gt;
	createAttribute(name): Creates Attr nodes of type Node.ATTRIBUTE_NODE&lt;br /&gt;
	createComment(data): Crates Comment nodes of type Node.COMMENT_NODE&lt;br /&gt;
	crateElement(tagName): Creates element nodes of type Node.ELEMENT_NODE&lt;br /&gt;
	createTextNode(date): Creates Text nodes of type Node.TEXT_NODE&lt;br /&gt;
	&lt;br /&gt;
	Locating Elements with Document methods:&lt;br /&gt;
	The getElementById('ID') method  returns one element corresponding to the ID. This method is singular and only returns one element.&lt;br /&gt;
	&lt;br /&gt;
	The getElementsByTagName('TAG') method returns a NodeList containing all the elements in the document with the same tag name as TAG. The NodeList is ordered by the order in which the Elements were encountered in a preorder traversal of the document tree. If TAG is *, all tags are matched.&lt;br /&gt;
	&lt;br /&gt;
	The importNode() method imports a node into this document from another document. The returned node has no parent node. A copy of source node is created, thus the source document is not affected in any way.  The Documents and DocumentTypes nodes cannot be imported.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Example DOM==&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
[[Image:domExample2.jpg]] &lt;br /&gt;
&amp;lt;/center&amp;gt;&lt;br /&gt;
==Algorithms==&lt;br /&gt;
&lt;br /&gt;
==Browser Support==&lt;br /&gt;
&lt;br /&gt;
==Applications==&lt;br /&gt;
&lt;br /&gt;
==Future DOM==&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Suggested Reading==&lt;br /&gt;
&lt;br /&gt;
==References / External Links==&lt;br /&gt;
&lt;br /&gt;
# Marcus Arnstrom, Mikael Christiansen, Daniel Sehlberg (May 2003),  ''Prototype-based programming''.&lt;br /&gt;
# Borning A (1986), ''Classes versus Prototypes in Object-Oriented Languages'', IEEE Computer Society Press, [http://portal.acm.org/citation.cfm?id=324538 In Proceedings of the IEEE/ACM Fall Joint Conference].&lt;br /&gt;
# [https://developer.mozilla.org/en/JavaScript/Guide/Details_of_the_Object_Model Prototype and Class based programming languages]&lt;br /&gt;
# [http://docstore.mik.ua/orelly/web/jscript/ch07_04.html Concept of Object Prototypes]&lt;br /&gt;
# [http://www.quirksmode.org/js/introevents.html Event Delegation with JavaScript]&lt;br /&gt;
# [http://www.grin.com/e-book/96313/the-newton-script-programming-language The NewtonScript Programming Language]&lt;br /&gt;
# [http://www.directessays.com/viewpaper/78763.html Prototype Theory]&lt;br /&gt;
# James Noble, Antero Taivalsaari, Ivan Moore, ''Prototype Based Programming - Concepts, Languages and Applications'' &lt;br /&gt;
# C. Dony, J. Malenfant, D. Bardon, [http://www.lirmm.fr/~dony/postscript/proto-book.pdf ''Classifying Prototype Based Languages'']&lt;br /&gt;
# [http://www.learn-javascript-tutorial.com/Prototype-Based-Inheritance.cfm Prototype-Based Inheritance]&lt;br /&gt;
# [http://en.wikipedia.org/wiki/Prototype-based_programming Criticism of prototype based programming languages]&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38212</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38212"/>
		<updated>2010-10-15T21:58:02Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented languages do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle those messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject does not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, which interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagram shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface. The SeatingCapacity and NoOfWheels methods are defined in the interface. But, the classes Car and Bus provide their own implementation of these methods. This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture. Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by a user of the system. The Controller takes the input from user and instructs the model to perform the required actions on it. The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38211</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38211"/>
		<updated>2010-10-15T21:55:16Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Message Forwarding */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented languages do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle those messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject does not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface. The SeatingCapacity and NoOfWheels methods are defined in the interface. But, the classes Car and Bus provide their own implementation of these methods. This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture. Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system. The Controller takes the input from user and instructs the model to perform the required actions on it. The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38208</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38208"/>
		<updated>2010-10-15T21:52:09Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Inheritance */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented languages do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface. The SeatingCapacity and NoOfWheels methods are defined in the interface. But, the classes Car and Bus provide their own implementation of these methods. This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture. Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system. The Controller takes the input from user and instructs the model to perform the required actions on it. The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38170</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38170"/>
		<updated>2010-10-15T18:33:49Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface. The SeatingCapacity and NoOfWheels methods are defined in the interface. But, the classes Car and Bus provide their own implementation of these methods. This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture. Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system. The Controller takes the input from user and instructs the model to perform the required actions on it. The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38169</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38169"/>
		<updated>2010-10-15T18:32:21Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface. The SeatingCapacity and NoOfWheels methods are defined in the interface. But, the classes Car and Bus provide their own implementation of these methods. This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture used in Ruby on Rails. &lt;br /&gt;
Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller&lt;br /&gt;
assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system.&lt;br /&gt;
The Controller takes the input from user and instructs the model to perform the required actions on it. &lt;br /&gt;
The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38168</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38168"/>
		<updated>2010-10-15T18:29:56Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface.&lt;br /&gt;
The SeatingCapacity and NoOfWheels methods are defined in the interface and no implementation for them is provided.&lt;br /&gt;
But, the classes Car and Bus provide their own implementation of these methods.&lt;br /&gt;
This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture used in Ruby on Rails. &lt;br /&gt;
Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller&lt;br /&gt;
assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system.&lt;br /&gt;
The Controller takes the input from user and instructs the model to perform the required actions on it. &lt;br /&gt;
The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38167</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38167"/>
		<updated>2010-10-15T18:28:49Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
Consider a case, when we wish to provide a class for Vehicles. Now, Car and Bus are types of vehicles. But each has its own Seating Capacity and the number of wheels is also different. If we do not have two different classes like Car and bus then, we have to add separate method for each type of vehicle with different names such as carSeatingCapacity(), busSeatingCapacity(), carNoOfWwheels(), and busNoOfWwheels() which will clutter the class.&lt;br /&gt;
 &lt;br /&gt;
A better solution is to use Object Oriented Decomposition. In this, we first find a subset of methods or properties that do not interact with the rest of the class. In this case, it would be the Seating Capacity and number of wheels. So, we just provide these methods in an interface and let the classes use this interface. Hence decomposition in different classes helps in reducing complexity of the design. Thus the main class is divided into smaller classes. &lt;br /&gt;
&lt;br /&gt;
The example below shows this concept:&lt;br /&gt;
&lt;br /&gt;
interface Vehicle&lt;br /&gt;
{&lt;br /&gt;
  void SeatingCapacity ();&lt;br /&gt;
  void NoOfwheels();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Car implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
     void SeatingCapacity()&lt;br /&gt;
     {&lt;br /&gt;
      // implementation for seating capacity of a car&lt;br /&gt;
     }&lt;br /&gt;
&lt;br /&gt;
     void NoOfwheels()&lt;br /&gt;
     {&lt;br /&gt;
       // implementation for number of wheels of a car&lt;br /&gt;
     }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
class Bus implements Vehicle&lt;br /&gt;
{&lt;br /&gt;
    void SeatingCapacity()&lt;br /&gt;
    {&lt;br /&gt;
        // implementation for seating capacity of a bus&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    void NoOfwheels()&lt;br /&gt;
    { &lt;br /&gt;
      // implementation for number of wheels of a bus&lt;br /&gt;
    }&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In above code, we have defined an interface Vehicle. Two classes Car and Bus implement this interface.&lt;br /&gt;
The SeatingCapacity and NoOfWheels methods are defined in the interface and no implementation for them is provided.&lt;br /&gt;
But, the classes Car and Bus provide their own implementation of these methods.&lt;br /&gt;
This shows how a system can be decomposed into smaller parts.&lt;br /&gt;
 &lt;br /&gt;
One other example of Decomposition is MVC ( Model-View-Controller ) architecture used in Ruby on Rails. &lt;br /&gt;
Here, first we analyze our system and come up with a different controller for each task. Thus, we have a specific controller&lt;br /&gt;
assigned for certain specific tasks. This makes the implementation easier and easy to manage. The View refers to the interface as seen by an user of the system.&lt;br /&gt;
The Controller takes the input from user and instructs the model to perform the required actions on it. &lt;br /&gt;
The Model interacts with the backend database to retrieve and update the required information. &lt;br /&gt;
&lt;br /&gt;
In C#, we can break down a class implementation into several class files and you divide your object the way you want.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38126</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38126"/>
		<updated>2010-10-15T17:19:37Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Decomposition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problems. In object oriented terminology, it is the process of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interact with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other words, if implementation of one of the function changes, all other functions which are dependent on this function also need to be changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in Object-Oriented Design is preferred. In this, we create well defined objects, who interact with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that a real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding, let's consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning of the system. Now if there is a problem with the wheel, this does not affect functionality of other objects. Only the central controller and the wheel need to implement the necessary changes.&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In Object Oriented Programming, Multiple Inheritance plays an important role. Languages like C++ allow Multiple Inheritance. In industry, to implement large systems this property is used frequently. However, due to well known diamond problem for Multiple Inheritance and complex hierarchy of the classes, programmers find less visibility of the functionality in an Inheritance tree. Hence, Decomposition is considered as a solution to these problems. To solve these issues, many researchers are working on finding reliable algorithms to decompose large Inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance, we need to define methods in Super class which can be used by objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect other modules. On the other hand, Inheritance binds two different classes so that change in one module breaks down most of the system.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38121</id>
		<title>CSC/ECE 517 Fall 2010/ch3 S30 PS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2010/ch3_S30_PS&amp;diff=38121"/>
		<updated>2010-10-15T17:12:09Z</updated>

		<summary type="html">&lt;p&gt;Champion: /* Message Forwarding */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''''Decomposition, Message Forwarding, and Delegation versus Inheritance in OOP Design'''''&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Object Oriented Programming concentrates on the design of a system using objects as individual entities which have different states and behaviors. Object Oriented Design (OOD) refers to the process of designing the objects and the level of interaction between those.&lt;br /&gt;
&lt;br /&gt;
Object Oriented Approach has advantages such as code is easy to maintain and it can be reused. Thus it ensures minimal duplication in system and improves the quality of the software. When we think of object oriented programming, Inheritance, Encapsulation, Polymorphism features attract our attention. However, there are many other alternatives to the traditional inheritance such as Delegation, Message Forwarding and Decomposition.&lt;br /&gt;
&lt;br /&gt;
Inheritance is the mechanism by which we can extract common functionality between hierarchical classes. A method can be implemented only once in a hierarchical class system and can be accessed through its descendants. Delegation deals with passing the execution control of method to another class at run time. Message Forwarding facilitates communication between different objects by sending and receiving messages. Decomposition is the technique of breaking complex problem into smaller parts so that they can be easily implemented and managed.&lt;br /&gt;
&lt;br /&gt;
In this chapter, we will explain the concept of Inheritance first, later we will contrast it with Delegation, Message Forwarding and Decomposition. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Inheritance ==&lt;br /&gt;
&lt;br /&gt;
Inheritance is a powerful concept in Object Oriented Programming which allows code reuse. In this, functionality of base class can be inherited by its subclasses. At the same time a subclass can have its own functionality.&lt;br /&gt;
&lt;br /&gt;
There two types of inheritance  &lt;br /&gt;
&lt;br /&gt;
'''Single Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property restricts that a class can only inherit from one class.  Java and Ruby are examples of object-oriented languages that have single inheritance.&lt;br /&gt;
&lt;br /&gt;
'''Multiple Inheritance'''&lt;br /&gt;
&lt;br /&gt;
This property allows a single class to inherit functionality from multiple classes. C++ allows Multiple Inheritance, however, the major drawback of this property is that it leads to the classical [http://en.wikipedia.org/wiki/Diamond_problem Diamond Multiple Inheritance Problem]. This is a primary reason why most of the other Object Oriented language's do not support Multiple Inheritance.&lt;br /&gt;
 &lt;br /&gt;
The concept of Inheritance can be better explained with a code in Ruby. &lt;br /&gt;
In ruby we have single Inheritance. &lt;br /&gt;
&lt;br /&gt;
''Example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Animal&lt;br /&gt;
  def sleep&lt;br /&gt;
    puts &amp;quot; I want to sleep &amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Herbivorous &amp;lt; Animal&lt;br /&gt;
  def eat&lt;br /&gt;
    puts &amp;quot; I want to eat plants &amp;quot;&lt;br /&gt;
   end&lt;br /&gt;
 end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Code execution''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
MyAnimal = Herbivorous.new&lt;br /&gt;
MyAnimal.sleep  #I want to sleep&lt;br /&gt;
MyAnimal.eat #I want to eat plants&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the class Herbivorous inherits class Animal. So when we create an object of the Herbivorous class we are able to inherit methods from the Animal class. Here is the simple UML diagram to explain inheritance.&lt;br /&gt;
&lt;br /&gt;
[[Image:Inheritance-s30.jpg|frame|center|UML diagram for inheritance]]&lt;br /&gt;
&lt;br /&gt;
'''When to use inheritance'''&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when there is an IS-A relationship between two classes. For example, Herbivorous is-an Animal.&lt;br /&gt;
&lt;br /&gt;
*When code re-usability is desired.&lt;br /&gt;
&lt;br /&gt;
*Inheritance is used when sub categories can be created from complex class.&lt;br /&gt;
&lt;br /&gt;
== Delegation ==&lt;br /&gt;
&lt;br /&gt;
As the word suggests, delegation means assigning the task to some other entity. In Object Oriented Programming terminology, it can be explained as, the process of passing execution control from one method to other method which can be in a different class. Delegation is also called as Dynamic Inheritance.&lt;br /&gt;
&lt;br /&gt;
Let’s say there are two objects A and B, A has some method and attributes, which B is interested in using. Thus, when two objects are not of the same type, above functionality can be achieved through Delegation. This mechanism is suitable when we have to decide which functionality needs to be invoked based on user input at run time.&lt;br /&gt;
&lt;br /&gt;
''Code example in Ruby''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
module Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    raise NotImplementedError.new&lt;br /&gt;
  end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
class Wheel&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot; Performs circular motion.&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Wing&lt;br /&gt;
  include Airplane&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    puts &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
  &lt;br /&gt;
class AirplaneActivity&lt;br /&gt;
  include Airplane&lt;br /&gt;
  def initialize&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
 &lt;br /&gt;
  def motion&lt;br /&gt;
    @var.motion&lt;br /&gt;
  end&lt;br /&gt;
  &lt;br /&gt;
  def setWing&lt;br /&gt;
    @var = Wing.new&lt;br /&gt;
  end&lt;br /&gt;
  def setWheel&lt;br /&gt;
    @var = Wheel.new&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above Ruby example creates a class ''Airplane'' which has method ''motion'' in it. This method throws ''NotImplementedError'' which indicates that there is no definition for this method. The classes ''Wheel'',''Wing'' and ''AirplaneActivity'' include the class ''Airplane'' in their definition and override ''motion'' method. In the class ''AirplaneActivity'', we provide  ''initialize'' method, which initializes the instance variable to an object of class ''Wing''. Also, the methods ''setWing'' and ''setWheel'' set different object values for instance variable ''@var''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
obj = AirplaneActivity.new&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Vertical motion&amp;quot;&lt;br /&gt;
obj.setWheel	# create new object of Wheel class&lt;br /&gt;
obj.motion	# output =&amp;gt; &amp;quot;Performs Circular motion&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is a sample test code which will reveal the Delegation behavior. The first statement creates an object obj of class ''AirPlaneActivity''. This calls the ''initialize'' method and creates a ''Wing'' class object. Next line invokes ''motion'' method of class ''AirPlaneActivity'' which in turn calls ''motion'' method of ''Wing'' class. This is possible because the current value of ''@var'' points to object of ''Wing'' class. In third line, using ''setWheel'', the ''@var'' value is set to ''Wheel's'' object. Due to this the ''motion'' method of ''Wheel'' class will get invoked. In this way, ''motion'' method of ''AirPlaneActivity'' class delegates control to different ''motion'' methods of ''Wing'' and ''Wheel'' class based on the value of ''@var'' instance variable. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Image:DelegationUML-s30.jpg|frame|center|UML diagram for delegation]]&lt;br /&gt;
&lt;br /&gt;
Above [http://en.wikipedia.org/wiki/Unified_Modeling_Language UML] diagram depicts the delegation pattern and its behavior at run-time. It also shows how all the classes are related to each other. &lt;br /&gt;
&lt;br /&gt;
'''Delegation Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Delegation is used when there is HAS-A relationship between two objects. For example, Airplane has an engine and wings. Relationship between all these three classes depicts the HAS-A relationship. Based on which activity to be monitored, corresponding motion() method is invoked. This is not the case with Inheritance, where to get a slightly different functionality, we have to over write the existing method.&lt;br /&gt;
&lt;br /&gt;
* Delegation should be used when the two objects are of different types but have some similar functionality. &lt;br /&gt;
&lt;br /&gt;
* Delegation can be used where components behave identically, but this situation may change over time.&lt;br /&gt;
&lt;br /&gt;
* Delegation leverages loose coupling in components and hence alteration of one component does not affect the system much. In Inheritance, on the other hand, there is a tight coupling between parent class and its children. Hence modification in parent's functionality may lead to logical error in all its children. &lt;br /&gt;
&lt;br /&gt;
* Delegation is sometimes called as Dynamic Inheritance as binding happens at run time. In above example, based on the object, corresponding methods are invoked. This is not the case with Inheritance as the objects to be invoked are determined during compilation. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls of delegation''' &lt;br /&gt;
&lt;br /&gt;
* Delegation increases code size as compared to Inheritance. In above code, we have written one interface and three classes to explain the concept of delegation.&lt;br /&gt;
&lt;br /&gt;
== Message Forwarding ==&lt;br /&gt;
&lt;br /&gt;
In Object Oriented Programming, Message Forwarding is one of the most powerful techniques. In this, when a message is sent to an object and if that object does not process that particular method, then instead of displaying an error, receiving object gets a second chance to process a message.  &lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Smalltalk SmallTalk] and [http://en.wikipedia.org/wiki/Objective-C Objective-C] supports this mechanism. &lt;br /&gt;
&lt;br /&gt;
Let’s look at a simple example which explains Message Forwarding. Say we have two classes ‘Nurse’ and ‘Doctor’.&lt;br /&gt;
&lt;br /&gt;
[[Image:Msgfws30.jpg|frame|center|Message forwarding ]]&lt;br /&gt;
&lt;br /&gt;
In above example, when the message for ‘operate’ comes to Nurse, it does not handle that messages as ‘Nurse don’t do operations alone and has to be done by doctor.’ Hence instead of giving an error, it forwards that message along with input parameters to the ‘Doctor’ object.  Doctor object handles operate method and return the response to Nurse object. From an abstract view, it appears that Nurse object is handling the message, but in reality, Doctor’s object is working on it. Message Forwarding simulates Multiple Inheritances in Object Oriented Programming as object that forwards message can inherit method from its super class and the class where it is forwarding the method. In other words, Nurse inherits functionality from its super class and Doctor class.&lt;br /&gt;
&lt;br /&gt;
For selection of different objects to forward the message, observer design pattern is used. Languages like [http://en.wikipedia.org/wiki/Objective-C objective-C] have extensive support for message forwarding. To implement this, [http://en.wikipedia.org/wiki/Observer_pattern observer design pattern] is used.&lt;br /&gt;
There are four parts to a message: a receiver object, a method name, optional method arguments, and an optional return value are to be handled.&lt;br /&gt;
&lt;br /&gt;
''Code example – objective -C'' &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
id newObject;                                 // could be any object;&lt;br /&gt;
  newObject = [[NewObject alloc] init];       // create and initialize the object&lt;br /&gt;
  [newObject doSomethingWith: anotherObject]; // send it a message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- (void) forwardInvocation: (NSInvocation*)anInvocation&lt;br /&gt;
{&lt;br /&gt;
  if ([anObject respondsToSelector: [anInvocation selector]])&lt;br /&gt;
    return [anInvocation invokeWithTarget: anObject];&lt;br /&gt;
  else&lt;br /&gt;
    return [self doesNotRecognizeSelector: [anInvocation selector]];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, newObject is an object and doSomethingWith is a method definition which is unknown to newObject. As the message to object binding happens at run-time, compiler will still compile the code. At run-time objective-C will find out that newObject did not recognize the doSomethingWith: message. Instead of giving error, the runtime sends another message to newObject as forwardInvocation: message. Now if newObject knows the anObject then it will forward. Self here refers to the object which receives the message, in the case its newobject.&lt;br /&gt;
&lt;br /&gt;
Message forwarding can also be simulated from other objected oriented languages. &lt;br /&gt;
&lt;br /&gt;
''Example using JavaScript''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// This code will instantiated object 'receiver' &lt;br /&gt;
// and call method 'receivingFunction'&lt;br /&gt;
&lt;br /&gt;
var  receiver = new someClass();&lt;br /&gt;
m(receiver, 'receivingFunction', someArgument);&lt;br /&gt;
&lt;br /&gt;
// object implements 'forwardInvocation' to send the message &lt;br /&gt;
// to next object.&lt;br /&gt;
&lt;br /&gt;
var class1 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object2;          // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class2 = new Class({&lt;br /&gt;
    forwardInvocation: function(){&lt;br /&gt;
        return object3;         // Forwarding&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
var class3 = new Class({&lt;br /&gt;
    receivingFunction: function(){&lt;br /&gt;
        return 'Message received.' //Actual message&lt;br /&gt;
    }&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
object1 = new class1();&lt;br /&gt;
object2 = new class2();&lt;br /&gt;
object3 = new class3();&lt;br /&gt;
&lt;br /&gt;
alert(m(object1, 'receivingFunction'));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In above code, alert message will send a message to obejct1 for handling 'receivingFunction'. As object1 does not handle it, it will send message to object2 and so on till actual function gets called. For this to work, we have to implement 'forwardInvocation' method for forwarding the message.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Message Forwarding Vs. Inheritance'''&lt;br /&gt;
&lt;br /&gt;
* Message Forwarding leverages functionality of reusing code of some other class. This functionality cannot be implemented using Inheritance as code reuse is done only in the inheritance hierarchy and not beyond that.&lt;br /&gt;
&lt;br /&gt;
* Compared to Inheritance, Message Forwarding provides privilege of loosely coupled design as different objects can communicate via exchange of messages. In Inheritance, there is always a tight coupling.&lt;br /&gt;
&lt;br /&gt;
* This helps data to be sent to objects of different classes in a very efficient manner. Languages like objective –C or SmallTalk have specific methods to implement this. Also Message Forwarding can be implemented with other object oriented languages like Java , Ruby and many more as shown in example above.&lt;br /&gt;
&lt;br /&gt;
* The change of a state in one object can be reflected in another object without keeping the objects tightly coupled.&lt;br /&gt;
&lt;br /&gt;
* In Inheritance, if we want custom implementation, then we have to override a method to provide new functionality, in which a method prototype can not be changed. If user wants to change prototype of a method, then all overridden methods have to be changed. In contrast to that, in Message Forwarding there are no dependencies between communicating objects, so no design changes are required.&lt;br /&gt;
&lt;br /&gt;
'''Pitfalls in Message Forwarding'''&lt;br /&gt;
&lt;br /&gt;
*In Message Forwarding, each argument has to allocate extra memory, however in Inheritance,  derived class uses references to arguments passed to the methods of parent class. As an example, if a big string (around 2000 characters) has to be passed as an argument, that much memory has to be allocated in Message Forwarding.  However, in Inheritance as all the objects are tightly coupled, sending an object reference is enough.&lt;br /&gt;
&lt;br /&gt;
== Decomposition ==&lt;br /&gt;
&lt;br /&gt;
Decomposition follows the divide and conquer strategy which helps to solve complex problem. In object oriented terminology, it is the method of breaking down bigger problem or system into smaller classes and objects which gives clear understanding of its functionality. The different parts of a systems after decomposition interacts with each other through well defined interfaces.&lt;br /&gt;
&lt;br /&gt;
In non-object oriented languages such as C, large systems can be broken down by writing different functions. This is called as functional decomposition, however there exists tight coupling across different functions. In other word, if implementation of one of the function changes, all other functions which are dependent on this function also need to changed. &lt;br /&gt;
&lt;br /&gt;
To avoid this problem, Decomposition in object-oriented design is preferred. In this, we create well defined objects, who interacts with each other through well defined interfaces. If the implementation in one of the objects changes then, only two objects between which the interaction takes place need to be changed. In sum, changes in one of the objects does not affect large portion of the system.&lt;br /&gt;
&lt;br /&gt;
[[Image:Decompose-s30.jpg|frame|center|Decomposition]]&lt;br /&gt;
&lt;br /&gt;
The above diagrams shows that the real world problem can be broken down in small objects and classes to manage the system.&lt;br /&gt;
For better understanding lets consider the above airplane system example. The airplane consists of wheel, wings, propellers, cockpit, etc. In Object Oriented Decomposition we create objects of these classes. Also we create an object Controller which interacts with all these objects and is responsible for the overall functioning the system. Now if there is a problem with the wheel, this does not affect the functionality of other objects. Only the central controller and the wheel need to implement the necessary changes. This does not affect the functionality of other objects.&lt;br /&gt;
&lt;br /&gt;
'''Inheritance vs Decomposition'''&lt;br /&gt;
&lt;br /&gt;
*In object oriented programming multiple inheritance plays an important role. Languages like C++ allowed multiple inheritances. In industry, to implement large systems this property is used frequently. However due to well known diamond problem for multiple inheritances and complex hierarchy of the classes programmers finds less visibility of the functionality in inheritance tree. Hence decomposition is considered as a solution to these problems. To solve these issues many researchers are working on finding reliable algorithms to decompose the large inheritance based hierarchical systems. M. Habib, M. Huchard  and J. Spinrad have covered these aspects in their paper named [http://www.springerlink.com/content/v3384m611187nl12/ A Linear Algorithm To Decompose Inheritance Graphs Into Modules]&lt;br /&gt;
&lt;br /&gt;
*In Inheritance we need to define methods in the Super class which can be used by the objects in sub class. This can be achieved by using the extends functionality in Java. Where as in case of Decomposition, objects define their own methods. So there is minimal dependency between interacting objects.&lt;br /&gt;
&lt;br /&gt;
*When the system is huge and the depth hierarchy tree is large, decomposition should be used. &lt;br /&gt;
&lt;br /&gt;
*When we want components of the system to be loosely coupled, changes made in one module should not affect the other module. On the other hand, inheritance bind two different classes so that change in one module brake down most of the system. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
Inheritance plays a vital role in object oriented programming to design more structured and reliable systems. However there are always some cases where inheritance is not a suitable option. &lt;br /&gt;
&lt;br /&gt;
Inheritance is tightly coupled. Inheritance is best suited when the size of the system is small. It is used when we have a IS-A relationship between the classes. As the number of classes in the system grows, we have to look for Decomposition of these classes into smaller ones. This modularized your system since the objects become loosely coupled.&lt;br /&gt;
&lt;br /&gt;
Delegation is used when we have a HAS-A relation between the classes. Delegation is a type of dynamic binding. Message Forwarding helps to reuse the code of some other class. The messages are passed at run time to invoke methods of other classes. &lt;br /&gt;
&lt;br /&gt;
Thus these OOD Principles help to design and implement the system in an effective manner. This article summarizes some of the alternatives to the traditional inheritance. Also we get guidance as when to use inheritance and when to consider different alternatives.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
Object Oriented Development by Grady Booch - http://www.ics.uci.edu/~taylor/classes/121/BoochOOD003.pdf&lt;br /&gt;
&lt;br /&gt;
Delegation (programming) -  http://en.wikipedia.org/wiki/Delegation_%28programming%29&lt;br /&gt;
&lt;br /&gt;
API documentation for Objective-C - http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSObject.html&lt;br /&gt;
&lt;br /&gt;
objective-C - http://en.wikipedia.org/wiki/Objective-C&lt;br /&gt;
&lt;br /&gt;
Decomposition - http://www.ibm.com/developerworks/webservices/library/ar-soastyle/&lt;br /&gt;
&lt;br /&gt;
Design Patterns: Elements of Reusable Object-Oriented Software - http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612&lt;br /&gt;
&lt;br /&gt;
Inheritance Decomposed - http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.5919&lt;br /&gt;
&lt;br /&gt;
Two object oriented decomposition methods, by V Rajlich 1988 - http://portal.acm.org/citation.cfm?id=339990&lt;br /&gt;
&lt;br /&gt;
Decomposition/Generalization Methods for Object Oriented Programming by Vaclav Rajlich J. - http://portal.acm.org/citation.cfm?id=179804&lt;br /&gt;
&lt;br /&gt;
Fundamentals of computer-aided engineering - http://www.amazon.com/Fundamentals-Computer-Aided-Engineering-Benny-Raphael/dp/0471487155&lt;br /&gt;
&lt;br /&gt;
Head First Object-Oriented Analysis and Design - http://www.amazon.com/Head-First-Object-Oriented-Analysis-Design/dp/0596008678/ref=sr_1_2?s=books&amp;amp;ie=UTF8&amp;amp;qid=1287108606&amp;amp;sr=1-2&lt;/div&gt;</summary>
		<author><name>Champion</name></author>
	</entry>
</feed>