Introduction to the Document Object Model Eugenia Fernandez IUPUI.

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
XPath Eugenia Fernandez IUPUI. XML Path Language (XPath) a data model for representing an XML document as an abstract node tree a mechanism for addressing.
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 18 The Document Object Model (DOM) is not a programming language It is an object-oriented model of web documents Each.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky.
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.
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science CSC 560: Management of XML Data.
 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.
SD2520 Databases using XML and JQuery
XML files (with LINQ). Introduction to LINQ ( Language Integrated Query ) C#’s new LINQ capabilities allow you to write query expressions that retrieve.
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.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Posting XML Data From the Client to a Server Eugenia Fernandez IUPUI.
JavaScript & DOM Client-side scripting. JavaScript JavaScript is a tool to automate client side (which is implemented using HTML so far) JavaSript syntax.
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.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
XQL, OQL and SQL Xia Tang Sixin Qian Shijun Shen Feb 18, 2000.
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.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Web-based Programming Lanjut Pertemuan 9 Matakuliah: M0492 / Web-based Programming Lanjut Tahun: 2007.
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.
Consuming eXtensible Markup Language (XML) feeds.
DOM Programming The Document Object Model standardises  what an application can see of the XML data  how it can access it An XML structure is a tree.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
1 Dr Alexiei Dingli XML Technologies SAX and DOM.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
Markup basics. Markup languages add commentary to text files –so that the commentary can be ignored if not understood eg HyperText Markup Language –adds.
Document Object Model. Back to the DOM… Javascript and the DOM  Originally, the Document Object Model (DOM) and Javascript were tightly bound  Each.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
XML DOM.
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.
Working with Elements and Attributes Using DOM Eugenia Fernandez IUPUI.
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.
DHTML.
XML for .NET Session 1 Introduction to XML Introduction to XSLT
In this session, you will learn to:
Unit 4 Representing Web Data: XML
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.
Week 11 Web site: XML DOM Week 11 Web site:
DOM Document Object Model.
Processing XML.
In this session, you will learn to:
More Sample XML By Sadia Anjum.
Document Object Model (DOM): Objects and Collections
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
Presentation transcript:

Introduction to the Document Object Model Eugenia Fernandez IUPUI

Document Object Model (DOM) XML DOM is an object model that exposes the contents of an XML document. Exposed means that the content of the document can be accessed and manipulated – via programs or scripts. The DOM defines a set of objects that allow the nodes of an XML document tree to be accessed and modified.

DOM Nodes NodeDescription NodeAny document component such as an element, attribute, comments or text string DocumentThe entire document, comprising all nodes ElementA document element AttrAn attribute of an element as a name/value pair ProcessingAny processing instruction encoded in the document InstructionComments, ignored by the parser TextText content of an element

The DOM Tree Structure Recall that an XML parser takes an XML document and creates a tree structure to represent the document. The tree structure shows the hierarchy of data in the XML document. DOCUMENT Document Element Attr Text Element Text

Everything is a Node Every ‘branch’ of the XML DOM tree is a Node object. Common Node methods firstChild, lastChild, nextSibling, previousSibling Common Node properties nodeValue nodeType nodeName NodenodeType value DocumentNODE_DOCUMENT ElementNODE_ELEMENT AttrNODE_ATTRIBUTE TextNODE_TEXT

Example The entire XML document is a Document node, and are Element nodes, title and isbn are Attr nodes, and the values “XML by Example” and “ ” are Text nodes.

Create the Document Object: Version 1 From XML data island The XMLDocument property of the data island provides a reference to the Document object Set doc = booksdso.XMLDocument

Create the Document Object: Version 2 From external XML file create a DOM document using the CreateObject method set the async property to False to indicate NOT to load the XML file asynchronously, if loaded async, the parser halts execution until the entire document is loaded load the XML file into the Document object alternatively, you can load an XML string instead of a file Set doc = CreateObject(“Microsoft.XMLDOM”) [or set doc = CreateObject(“MSXML2.DOMDocument”)] doc.async = False doc.load “Books.xml” doc.load “ ”

Accessing Nodes Within a DOM object, once you access a particular node you can use its properties/methods to determine its location in the document tree child nodes parent node siblings and ancestors attributes Accessing the root element set rootNode = doc.documentElement

Node Properties & Methods nodeType, nodeName, nodeValue parentNode parent node, if any childNode set of child nodes firstChild, lastChild previousSibling, nextSibling attributes set of attributes of the current node, if any

Navigating Elements DOCUMENT theNode theNode.parentNode.lastChild theNode.parentNode.childNodes(0) theNode.parentNode theNode.ownerDocument theNode.nextSibling

Collections Each node potentially has a collection, or set, of child nodes. Collections have methods used to traverse the nodes sequentially. Numbering starts at 0.

Navigating Node Collections childNodes property returns a NodeList object – a zero-based collection of nodes set doc = booksdso.XMLDocument set rootnode = doc.documentElement for each child in rootNode.childNodes ‘process data in child node next ‘or set children = rootNode.childNodes for I=0 to children.length-1 ‘process data in children.item(I) Next

Retrieving Node Content nodeType type of node expressed by number 9 = document node 1 = element node 2 = attribute node nodeName name of the node

Retrieving a Node’s Value nodeValue value of a text node or attribute node The nodeValue of an element is null. Its text is held in a child text node. To retrieve its value, you must retrieve the value of first child. set title = rootNode.firstChild.childNodes(0) set titleValue = title.firstChild.nodeValue

The Document Object The topmost node in a DOM tree (NOT the root XML element, but above that – represents the entire document) This is set by the creation of the DOM tree (either version 1 or version 2). Has two properties: documentElement this is the root element of the XML document accessed as doc.documentElement doctype not specified in DOM level 1

The Element Object Represents XML elements Adds new property: tagName Adds new method getElementByTagName() returns a node set of all descendants of the element with a given tag name

Accessing Attributes Use the attributes property to access the value of attributes Example This retrieves the value of the first attribute of the first child node of the root element (doc.documentElement) doc.documentElement.firstChild.attributes(0).value

Microsoft Extensions nodeTypeString type of node expressed as a string, e.g. “document”, “element”, “attribute” text returns text content of the node and all its descendants xml returns XML of the node and all its descendants

Viewing XML Data Microsoft’s DOM defines an xml property in the Node object. This allows you to retrieve the XML data contained in that portion of the tree, i.e. the subtree that starts at the selected node. Msgbox booksdso.XMLDocument.xml Msgbox booksdso.XMLDocument.document element.xml

Source “Building XML-Based Web Applications” a Microsoft Certified Course.