1 XML Data Management 4. Domain Object Model Werner Nutt.

Slides:



Advertisements
Similar presentations
The Document Object Model
Advertisements

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.
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.
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.
1 Processing XML with Java Dr. Praveen Madiraju Modified from Dr.Sagiv ’ s slides.
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.
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)
1 Document Object Model (DOM) MV4920 – XML 24 September 2001 Simon R. Goerger MAJ, US Army
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.
Lecture 2 : Understanding the Document Object Model (DOM) UFCFR Advanced Topics in Web Development II 2014/15 SHAPE Hong Kong.
17 Apr 2002 XML Programming - DOM Andy Clark. DOM Design Premise Derived from browser document model Defined in IDL – Lowest common denominator programming.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
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.
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.
SDPL 2002Notes 3.2: Document Object Model1 3.2 Document Object Model (DOM) n How to provide uniform access to structured documents in diverse applications.
1 Processing XML with Java Modified from Dr.Sagiv ’ s slides.
Consuming eXtensible Markup Language (XML) feeds.
Consuming eXtensible Markup Language (XML) feeds.
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.
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.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
(1) JavaScript. (2) JavaScript vs. Java JavaScript and Java are completely different Java, invented by Sun in 1995, is a complex programming language.
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
XML DOM.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
DOM (Document Object Model) - Parsing and Reading HTML and XML -
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.
13-Mar-16 DOM. 2 Difference between SAX and DOM DOM reads the entire XML document into memory and stores it as a tree data structure SAX reads the XML.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
XML DOM Week 11 Web site:
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.
DHTML.
Unit 4 Representing Web Data: XML
Introduction to the Document Object Model
DOM Robin Burke ECT 360.
Java/XML.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Chapter 7 Representing Web Data: XML
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.
DOM 24-Feb-19.
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
Presentation transcript:

1 XML Data Management 4. Domain Object Model Werner Nutt

Domain Object Model (DOM) XML and HTML documents are (long) strings, physically represent trees  applications should manipulate documents abstractly as trees  define a tree API W3C: DOM is a platform and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. The document can be further processed and the results can be incorporated back into the presented page

Document Holidays for Austria New Year's Day Christmas

DOM Tree Source:

DOM Specifications Level 0 (1996), Netscape et al. Facilities for modifying HTML documents on the client side in response to user-generated events Level 1 (1998), W3C Rec Abstract tree model, capturing HTML and XML Functionality for navigating and manipulating documents Level 2 (2000), W3C Recommendation Adds a style object to DOM, defines an event model, supports namespaces Level 2 Core: API to access and update content and structure of docs Level 2 HTML: API for HTML plus Level 2 Views, Style, Events,... Level 3 (2004) API for content models (DTD and Schemas) and XPath

DOM Objects and Interfaces Every component of a document is represented as an object Every object is an instance of a class The class interface defines the attributes and methods E.g., class Element has methods setAttribute(String name, String value) DOM interface is specified in IDL (= Interface Definition Language) Bindings for a variety of languages: Java, JavaScript, PHP, C++, VBScript, etc. The tree model underlying XPath is similar to DOM trees

Starting Point: The Node Interface (1) interface Node { // Node Type 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; // The top node of the tree const unsigned short DOCUMENT_NODE = 9; // Represents the DTD of the document const unsigned short DOCUMENT_TYPE_NODE = 10; const unsigned short DOCUMENT_FRAGMENT_NODE = 11; const unsigned short NOTATION_NODE = 12;

Starting Point: The Node Interface (2) // Getting info about nodes readonly attribute DOMString nodeName; attribute DOMString nodeValue; // raises(DOMException) on setting // raises(DOMException) on retrieval // More info about nodes readonly attribute unsigned short nodeType; // Node navigation 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;

Starting Point: The Node Interface (3) // Methods to manipulate nodes 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();

Starting Point: The Node Interface (4) Node cloneNode(in boolean deep); // Merge adjacent text nodes etc. void normalize(); // tests DOM implementation for feature // e.g., isSupported('XHTML', '2.0') boolean isSupported(in DOMString feature, in DOMString version); // Namespace of the element readonly attribute DOMString namespaceURI; // Introduced in DOM Level 2: attribute DOMString prefix; readonly attribute DOMString localName; boolean hasAttributes(); };

DOM Node Interfaces: Overview

Node Interface: Comments Not all methods are applicable to all nodes –E.g., appendChild for a text node leads to an exception  when in doubt, check the node type Not all node attributes have a value –E.g., a comment does not have a name, the value is null  see table on next slide for nodeNames and nodeValues

InterfacenodeNamenodeValue Attrname of attributevalue of attribute CDATASection#cdata-section content of the CDATA Section Comment#commentcontent of the comment Document#documentnull DocumentFragment#document-fragmentnull DocumentTypedocument type namenull Elementtag namenull Entityentity namenull EntityReferencename of entity referencednull Notationnotation namenull Processing Instructiontarget entire content excluding the target Text#textcontent of the text node

DOM Tree: Example Hello, Ladies and Gentlemen CommentElement Text Element Text Attribute Document

Element, Text Elements can have children (Elements and Text) can have attributes Text inherits from Character Data (substringData, insertData) contains as data a DomString –sequence of 16-bit units –coded in UTF-16 (= Unicode Transformation Format)

Attribute Nodes Different from Elements attributes are not children of a node (rather properties) –no sibling and parent relationships  accessible by element navigation –no ordering among attributes  access by name attributes can have values (but need not) –assigned values –default values (from DTD)

Document: The Mother of all Nodes The root of the DOM tree is a node of type Document access point for the data in the tree: “owner document” of the nodes contained provides factory methods for the generation of other nodes distinct from root element of the document children: –Element –possibly DocumentType, Comment, ProcessingInstruction, etc.

Document (cntd) 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);

Document (cntd) EntityReference createEntityReference(in DOMString name) raises(DOMException); NodeList getElementsByTagName(in DOMString tagname); Node importNode(in Node importedNode, in boolean deep) raises(DOMException); Element createElementNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException); Attr createAttributeNS(in DOMString namespaceURI, in DOMString qualifiedName) raises(DOMException); NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); Element getElementById(in DOMString elementId); };

Java API for XML Processing (JAXP) Implements DOM (and SAX/StAX parsing interfaces + XSLT) Packages org.w3c.dom –contains Java version of DOM interfaces –Java binding for DOM javax.xml.parsers contains classes –DocumentBuilder: creates instances of Document –DocumentBuilderFactory: creates instances of DocumentBuilder