Document Object Model. Lecture 18 The Document Object Model (DOM) is not a programming language It is an object-oriented model of web documents Each.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.
Advertisements

XML IV. The Document Object Model The Document Object model is a hierarchical structure of an XML document. It provides a means for accessing, and manipulating.
The Document Object Model
DOM. Document Object Model • Orginalt DOM for JavaScript – Manipulere dokumenter dynamisk i nettleser • Språknøytral API – OMG IDL • Standard for å –
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky.
PHP and the DOM There was some experimental support for the DOM in PHP 4 But it is only with PHP 5 that support appears to have stabilized At present,
11-Jun-15 More DOM. Manipulating DOM trees DOM, unlike SAX, gives you the ability to create and modify XML trees There are a few roadblocks along the.
14-Jun-15 DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard SAX is an ad-hoc.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
Document Object Model. Lecture 19 Does the last paragraph node have any children? My Document function report() { if (document.getElementsByTagName("p").
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science CSC 560: Management of XML Data.
1 Processing XML with Java Representation and Management of Data on the Internet A comprehensive tutorial about XML processing with JavaXML processing.
1 Processing XML with Java CS , Spring 2008/9.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
Processing of structured documents Spring 2003, Part 5 Helena Ahonen-Myka.
C# The new language for Updated by Pavel Ježek © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
1 XML Data Management 4. Domain Object Model Werner Nutt.
HTML DOM.  The HTML DOM defines a standard way for accessing and manipulating HTML documents.  The DOM presents an HTML document as a tree- structure.
JS: Document Object Model (DOM)
5 Processing XML Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview.
Stein XML 2.1 XML a first course Part 2 Yaakov J. Stein Chief Scientist RAD Data Communications.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
17 Apr 2002 XML Programming - DOM Andy Clark. DOM Design Premise Derived from browser document model Defined in IDL – Lowest common denominator programming.
Parsing with DOM using MSXML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
DOM Robin Burke ECT 360. Outline XHTML in Schema JavaScript DOM (MSXML) Loading/Parsing Transforming parameter passing DOM operations extracting data.
Fall 2006 Florida Atlantic University Department of Computer Science & Engineering COP 4814 – Web Services Dr. Roy Levow Part 4 - XML.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
The XML Document Object Model (DOM) Aug’10 – Dec ’10.
5.2 DOM (Document Object Model). 2 Motto: To write it, it took three months; to conceive it three minutes; to collect the data in it — all my life. —F.
WORKING WITH XML IN THE.NET FRAMEWORK. Accessing an XML File Basic activities: open it, read it.NET Framework provides structured and unstructured mechanisms.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
Navigating the DOM with ExtJS By Aaron Conran. Document Object Model The Document Object Model or DOM is a standard to represent HTML, XHTML and other.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
1 DHTML and DOM. 2 Style Sheets: CSS and CSS2 W3C recommendation on Cascading Style Sheet CSS level 1 specification allows expressing style of contents.
SDPLNotes 3.2: DOM1 3.2 Document Object Model (DOM) n How to provide uniform access to structured documents in diverse applications (parsers, browsers,
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
Markup basics. Markup languages add commentary to text files –so that the commentary can be ignored if not understood eg HyperText Markup Language –adds.
(1) JavaScript. (2) JavaScript vs. Java JavaScript and Java are completely different Java, invented by Sun in 1995, is a complex programming language.
XML DOM.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
Host Objects: Browsers and the DOM
Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.
Create Element, Remove Child. The Document Tree Document Element Root Element Element Element Element Element Text: HelloWorld Attribute “href”
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
XML DOM Week 11 Web site:
DOM Dr. Reda Salama. Back to the HTML DOM Once we get a response back from the server, we probably want to update our HTML page The HTML page itself is.
Introduction to JavaScript DOM Instructor: Sergey Goldman.
21-Jun-16 Document Object Model DOM. SAX and DOM SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C.
Introduction to JavaScript DOM and Events
DHTML.
CHAPTER 5 DOCUMENT OBJECT MODEL
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
Applied Online Programming
Introduction to the Document Object Model
DOM Robin Burke ECT 360.
COMP3220 Web Infrastructure COMP6218 Web Architecture
Jim Fawcett CSE686 – Internet Programming Summer 2010
More DOM 13-Nov-18.
Geoffrey Fox and Bryan Carpenter PTLIU Laboratory for Community Grids
Week 11 Web site: XML DOM Week 11 Web site:
DOM Document Object Model.
DOM Document Object Model.
More DOM 28-Nov-18.
In this session, you will learn to:
More DOM.
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
Presentation transcript:

Document Object Model

Lecture 18

The Document Object Model (DOM) is not a programming language It is an object-oriented model of web documents Each web document is regarded as an instance of an object class, with –attributes and –Methods Although the DOM is not a language, there can be several language bindings for it –in particular, there is a Javascript binding –That is, one can access the DOM from JavaScript

DOM Level 0 The DOM Level 0 is a name that is sometimes given to various object models that were used by different browsers before the W3C started to standardize the DOM –For example, there was a Netscape DOM, which was accessible through JavaScript –There was also a Microsoft DOM which was different in some respects from the Netscape DOM

The W3C DOM W3C DOM Level 1 (2 documents, Sept 2000) –DOM Level 1 Core –DOM Level 1 HTML W3C DOM Level 2 (4 documents, Nov ) –DOM Level 2 Core –DOM Level 2 HTML –DOM Level 2 Events –DOM Level 2 Style W3C DOM Level 3 (2 documents, ) –DOM Level 3 Core –DOM Level 3 Events –DOM Level 3 Load and Save Specification –DOM Level 3 XPath Specification

DOM Level 1 Core This provides a set of core facilities for reading, writing and changing the contents of documents The facilities apply equally well to HTML and XML They are also intended to provide a basis for future web applications

The Document node This represents the entire document (XML or HTML). Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

Formal spec for the Document node interface Document : Node { readonly attribute DocumentType doctype; readonly attribute DOMImplementation implementation; readonly attribute Element documentElement; Element createElement(in DOMString tagName) raises(DOMException); DocumentFragment createDocumentFragment(); Text createTextNode(in DOMString data); Comment createComment(in DOMString data); CDATASection createCDATASection(in DOMString data) raises(DOMException); ProcessingInstruction createProcessingInstruction(in DOMString target, in DOMString data) raises(DOMException); Attr createAttribute(in DOMString name) raises(DOMException); EntityReference createEntityReference(in DOMString name) raises(DOMException); NodeList getElementsByTagName(in DOMString tagname); };

Formal spec for the Document node Thus, the Document node provides three attributes and nine methods Attributes Doctype implementation documentElement Methods createElement(in DOMString tagName) createDocumentFragment(); createTextNode(in DOMString data); createComment(in DOMString data); createCDATASection(in DOMString data) createProcessingInstruction(in DOMString target, in DOMString data) createAttribute(in DOMString name) createEntityReference(in DOMString name) getElementsByTagName(in DOMString tagname);

A simple HTML document My Document My first header My first paragraph My second header My second paragraph My third paragraph

Counting the number of headers Suppose we want to count the number of H1 headers in this document We could use the getElementsByTagName() method, but this returns a NodeList so we need to know how to see how many members are in this list We need the formal model for the NodeList

Formal spec for the nodeList node interface NodeList { readonly attribute unsigned long length; Node item(in unsigned long index); }; Thus, a NodeList has 1 attribute and 1 method The attribute length is the number of nodes in the list The method item() returns a node in the list

An extended version of the document My Document function report() {alert("There are "+ document.getElementsByTagName("h1").length+ " headers"); } My first header My first paragraph My second header My second paragraph My third paragraph Click to get a report

Manipulating individual nodes Each member of a nodeList is a Node So, we need the formal model for a Node

Formal spec for the Node node (part 1) interface Node { // NodeType const unsigned short ELEMENT_NODE = 1; const unsigned short ATTRIBUTE_NODE = 2; const unsigned short TEXT_NODE = 3; const unsigned short CDATA_SECTION_NODE = 4; const unsigned short ENTITY_REFERENCE_NODE = 5; const unsigned short ENTITY_NODE = 6; const unsigned short PROCESSING_INSTRUCTION_NODE = 7; const unsigned short COMMENT_NODE = 8; const unsigned short DOCUMENT_NODE = 9; const unsigned short DOCUMENT_TYPE_NODE = 10; const unsigned short DOCUMENT_FRAGMENT_NODE = 11; const unsigned short NOTATION_NODE = 12;

Formal spec for the Node node (part 2) readonly attribute DOMString nodeName; attribute DOMString nodeValue; // raises(DOMException) on setting or retrieval readonly attribute Node parentNode; readonly attribute NodeList childNodes; readonly attribute Node firstChild; readonly attribute Node lastChild; readonly attribute Node previousSibling; readonly attribute Node nextSibling; readonly attribute NamedNodeMap attributes; readonly attribute Document ownerDocument; Node insertBefore(in Node newChild, in Node refChild) raises(DOMException); Node replaceChild(in Node newChild, in Node oldChild) raises(DOMException); Node removeChild(in Node oldChild) raises(DOMException); Node appendChild(in Node newChild) raises(DOMException); boolean hasChildNodes(); Node cloneNode(in boolean deep); };

Attributes and methods of a Node node There are eleven attributes: nodeType nodeName nodeValue parentNode childNodes firstChild lastChild previousSibling nextSibling attributes ownerDocument There are six methods : insertBefore(in Node newChild, in Node refChild) replaceChild(in Node newChild, in Node oldChild) removeChild(in Node oldChild) appendChild(in Node newChild) hasChildNodes(); cloneNode(in boolean deep);

Inspecting the type of the last paragraph node My Document function report() { alert(document.getElementsByTagName("p"). item(document.getElementsByTagName("p").length-1).nodeType); } Show nodeType of last paragraph My first header My first paragraph My second paragraph My second header My third paragraph My fourth paragraph

Inspecting the type of the last paragraph node (contd) We have seen that the nodeType of the last paragraph node is 1, which means that it is an ELEMENT_NODE