Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.

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
Internet Technologies1 1 Lecture 4: Programming with XSLT.
JavaScript and the DOM Les Carr COMP3001 Les Carr COMP3001.
Tutorial 16 Working with Dynamic Content and Styles.
1 Extensible Markup Language: XML HTML: portable, widely supported protocol for describing how to format data XML: portable, widely supported protocol.
XML DOM and SAX Parsers By Omar RABI. Introduction to parsers  The word parser comes from compilers  In a compiler, a parser is the module that reads.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
1 Extensible Markup Language: XML HTML: widely supported protocol for formatting data XML: widely supported protocol for describing data XML is quickly.
Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.
By: Shawn Li. OUTLINE XML Definition HTML vs. XML Advantage of XML Facts Utilization SAX Definition DOM Definition History Comparison between SAX and.
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.
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)
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
DOM and JavaScript Aryo Pinandito.
Lecture 11 – DOM Scripting SFDV3011 – Advanced Web Development Reference: 1.
CIS 375—Web App Dev II DOM. 2 Introduction to DOM The XML Document ________ Model (DOM) is a programming interface for XML documents. It defines the way.
Parsing with DOM using MSXML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Tutorial 1: XML Creating an XML Document. 2 Introducing XML XML stands for Extensible Markup Language. A markup language specifies the structure and content.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
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.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
Javascript II DOM & JSON. In an effort to create increasingly interactive experiences on the web, programmers wanted access to the functionality of browsers.
XML Document Object Model Anthony Borquez. The Document Object Model a programming interface for HTML and XML documents. It defines the way a document.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
XP Tutorial 16 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
XML Study-Session: Part III
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
 2008 Pearson Education, Inc. All rights reserved Document Object Model (DOM): Objects and Collections.
Review of the DOM Node properties and methods Some ways of accessing nodes Appending, copying and removing nodes Event handling – Inline – Scripting –
XML Parser using JavaScript. 2 Microsoft To manipulate an XML document in javascript, you need an XML parser. Today all browsers come with in-built parsers.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
XML and Object Serialization. Structure of an XML Document Header Root Element Start Tags / End Tags Element Contents – Child Elements – Text – Both (mixed.
CO1552 – Web Application Development Further JavaScript: Part 1: The Document Object Model Part 2: Functions and Events.
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
Document Object Model (DOM). Outline  Introduction of DOM  Overview of DOM  DOM Relationships  Standard DOM.
Computer Information System Information System California State University Los Angeles Jongwook Woo CIS 461 Web Development I HTML DOM part I Jongwook.
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.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
XP Tutorial 10 New Perspectives on JavaScript, Comprehensive 1 Working with Dynamic Content and Styles Creating a Dynamic Table of Contents.
THE DOM.
DHTML.
In this session, you will learn to:
Unit M Programming Web Pages with
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.
Unit M Programming Web Pages with
Week 11 Web site: XML DOM Week 11 Web site:
DOM Document Object Model.
DOM Document Object Model.
Processing XML.
In this session, you will learn to:
2017, Fall Pusan National University Ki-Joune Li
CS 240 – Advanced Programming Concepts
Presentation transcript:

Document Object Model

 The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an XML document as a tree structure, with elements, attributes, and text as nodes.

 DOM is a standard defined by the W3C, just like XML  DOM was not designed specifically for Java technology (unlike SAX)  DOM is cross-platform and cross language  Uses OMG’s IDL to define interfaces  IDL to language binding

 Access XML document as a tree structure  Composed of mostly element nodes and text nodes  Can “walk” the tree back and forth  Larger memory requirements  Fairly heavyweight to load and store  Use it when for walking and modifying the tree

XML Document Parser Creates Tree Input

 XML document is represented as a tree  A tree is made of nodes  There are 12 different node types  Nodes may contain other nodes (depending on node types)  parent node contains child nodes

 Document node  Document Fragment node  Element node  Attribute node  Text node  Comment node  Processing instruction node  Document type node  Entity node  Entity reference node  CDATA section node  Notation node

 A document node contains  one element node (root element node)  one or more processing instruction nodes  An element node may contain  other element nodes  one or more text nodes  one or more attribute nodes  An attribute node contain  a text node

Alan Turing computer scientist

 XML Document node  element node “people”  element node “person”  element node “name”  element node “first_name” * text node “Alan” » element node “last_name” * text node “Turing”  element node “profession” » text node “computer scientist”  attribute node “born” » text node “1912”

 All modern browsers have a build-in XML parser that can be used to read and manipulate XML.  The parser reads XML into memory and converts it into an XML DOM object that can be accesses with JavaScript

xmlDoc=new ActiveXObject ("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load(“people.xml");  Code explained:  The first line creates an empty Microsoft XML document object.  The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.  The third line tells the parser to load an XML document called “people.xml".

Programming Interface  The DOM models XML as a set of node objects. The nodes can be accessed with JavaScript or other programming languages.  The programming interface to the DOM is defined by a set standard properties and methods.  Properties are often referred to as something that is (i.e. nodename is “name").  Methods are often referred to as something that is done (i.e. delete “name").

XML DOM Properties  These are some typical DOM properties:  x.nodeName - the name of x  x.nodeValue - the value of x  x.parentNode - the parent node of x  x.childNodes - the child nodes of x  x.attributes - the attributes nodes of x

XML DOM Methods  x.getElementsByTagName( name ) - get all elements with a specified tag name  x.appendChild( node ) - insert a child node to x  x.removeChild( node ) - remove a child node from x

 Accessing Nodes  You can access a node in three ways: 1. By using the getElementsByTagName() method 2. By looping through (traversing) the nodes tree. 3. By navigating the node tree, using the node relationships

 The JavaScript code to get the text from the first element in people.xml:  txt=xmlDoc.getElementsByTagName(“name")[ 0].childNodes[0].nodeValue

 After the execution of the statement, txt will hold the value “Alan" Explained:  xmlDoc - the XML DOM object created by the parser.  getElementsByTagName(“Name")[0] - the first element  childNodes[0] - the first child of the element (the text node)  nodeValue - the value of the node (the text itself)

DOM Node List Length  The length property defines the length of a node list (the number of nodes).  You can loop through a node list by using the length property: xmlDoc=loadXMLDoc(“people.xml"); x=xmlDoc.getElementsByTagName(“name"); for (i=0;i<x.length;i++) { document.write(x[i].childNodes[0].nodeValue); document.write(" "); }

Example explained:  Load “people.xml" into xmlDoc.xml  Get all element nodes  For each title element, output the value of its text node

Node Types  The documentElement property of the XML document is the root node.  The nodeName property of a node is the name of the node.  The nodeType property of a node is the type of the node.

xmlDoc=loadXMLDoc(“people.xml"); x=xmlDoc.documentElement.childNodes; for (i=0;i<x.length;i++) { if (x[i].nodeType==1) {//Process only element nodes (type 1) document.write(x[i].nodeName); document.write(" "); }

Example explained:  Load “people.xml" into xmlDoc.  Get the child nodes of the root element  For each child node, check the node type of the node. If the node type is "1" it is an element node  Output the name of the node if it is an element node

Get the Value of an Element xmlDoc=loadXMLDoc(“people.xml"); x=xmlDoc.getElementsByTagName("title")[0].c hildNodes[0]; txt=x.nodeValue; x.nodeValue=“charles";

The nodeType Property  The nodeType property specifies the type of node.  nodeType is read only.  The most important node types are: