5 Processing XML 5 - 2 Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview.

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

The Document Object Model
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.
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.
SAX A parser for XML Documents. XML Parsers What is an XML parser? –Software that reads and parses XML –Passes data to the invoking application –The application.
1 XML and Data Management XML Processors Hachim Haddouti Al Akhawayn University SSE
XML Parser. Why Need a XML Parser ? Check XML syntax. ( is well-formed ? ) Validation. ( DTD and XML Schema ) Allow programmatic access to the document’s.
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.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 05: XML Professor Chen Li Department of Computer Science UC Irvine CS122BNotes 05:
1 XML Data Management 4. Domain Object Model Werner Nutt.
JS: Document Object Model (DOM)
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.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
SDPL 2002Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
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.
XML 6.4 DOM 6. The XML ‘Alphabet Soup’ XMLExtensible Markup Language Defines XML documents XSLExtensible Stylesheet Language Language for expressing stylesheets;
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.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
1 Processing XML with Java Modified from Dr.Sagiv ’ s slides.
JavaScript IV ECT 270 Robin Burke. Outline DOM JS document model review W3C DOM.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
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.
SNU OOPSLA Lab. DOM/SAX Applications The ubiquitous XML(9) © copyright 2001 SNU OOPSLA Lab.
Java and XML. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information about a document. Tags are added.
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.
SAX2 and DOM2 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
XML DOM.
Working with Elements and Attributes Using DOM Eugenia Fernandez IUPUI.
Processing of structured documents Part 4. XML processing model zXML processor is used to read XML documents and provide access to their content and structure.
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.
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.
Java API for XML Processing
THE DOM.
Introduction to JavaScript DOM and Events
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
In this session, you will learn to:
Scripting the DOM MIS 3502, Fall 2016 Jeremy Shafer Department of MIS
Introduction to the Document Object Model
DOM Robin Burke ECT 360.
More DOM 13-Nov-18.
DOM Document Object Model.
DOM Document Object Model.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
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:

5 Processing XML

5 - 2 Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview

5 - 3 What's the Problem? The XML Handbook Goldfarb Prescod Prentice Hall XML Design Spencer Wrox Press... ? Book ?

5 - 4 Parsing XML Documents Document Tree Parser Docu- ment DTD / Schema Application implements DocumentHandler endDocument startDocument endElement startElement DOM SAX

5 - 5 Parser Project X (Sun Microsystems) Ælfred (Microstar Software) XML4J (IBM) Lark (Tim Bray) MSXML (Microsoft) XJ (Data Channel) Xerces (Apache)...

5 - 6 Prescod book Prentice Hall The XML Handbook Goldfarb Prescod Prentice Hall XML Design Spencer Wrox Press... The Document Object Model XML Document Structure The XML Handbook Goldfarb655 books book publisherpagesisbnauthortitle...

5 - 7 The Document Object Model Provides a standard interface for access to and manipulation of XML structures. Represents documents in the form of a hierarchy of nodes. Is platform- and programming-language-neutral Is a recommendation of the W3C (October 1, 1998) Is implemented by many parsers

5 - 8 DOM - Structure Model Document Node NodeList Element Prescod book Prentice Hall The XML Handbook Goldfarb655 books book publisherpagesisbnauthortitle...

5 - 9 The Document Interface Method Result docType implementation documentElement getElementsByTagName(String) createTextNode(String) createComment(String) createElement(String) create CDATASection(String) DocumentType DOMImplementation Element NodeList String Comment Element CDATASection

The Node Interface Method Result nodeName nodeValue nodeType parentNode childNodes firstChild lastChild previousSibling nextSibling attributes insertBefore(Node new,Node ref) replaceChild(Node new,Node old) removeChild(Node) hasChildNode String short Node NodeList Node NodeNamedMap Node Boolean

Node Types / Node Names Result: NodeType /NodeName Node Node Node Fields Type Name ELEMENT_NODE 1 tagName ATTRIBUTE_NODE 2 name of attribute TEXT_NODE 3 "#text" CDATA_SECTION_NODE 4 "#cdata-section" ENTITY_REFERENCE_NODE 5 name of entity referenced ENTITY_NODE 6 entity name PROCESSING_INSTRUCTION_NODE 7 target COMMENT_NODE 8 "#comment" DOCUMENT_NODE 9 "#document" DOCUMENT_TYPE_NODE10 document type name DOCUMENT_FRAGMENT_NODE11 "#document-fragment" NOTATION_NODE12 notation name

The NodeList Interface Method Result length item(int) Int Node

The Element Interface Method Result tagName getAttribute(String) setAttribute(String name, String value) removeAttribute(String) getAttributeNode(String) setAttributeNode(Attr) removeAttributeNode(String) getElementsByTagName String Attr NodeList

DOM Methods for Navigation firstChildlastChild nextSiblingpreviousSibling parentNode getElementsByTagName childNodes (length, item())

DOM Methods for Manipulation appendChild insertBefore replaceChild removeChild createElement createAttribute createTextNode

Example Goldfarb Spencer books book author Prescod doc.documentElement.childNodes.item(0).getElementsByTagName("author"). item(1).childNodes.item(0).data doc.documentElement.childNodes.item(0).getElementsByTagName("author"). item(1).childNodes.item(0).data Root Node DOM Object TextBooks second Author Text Subnodes first thereof first Book Authors

Script DOM Example DOM Example var doc, root, book1, authors, author2; doc = new ActiveXObject("Microsoft.XMLDOM"); doc.async = false; doc.load("books.xml"); if (doc.parseError != 0) alert(doc.parseError.reason); else { root = doc.documentElement; document.write("Name of Root node: " + root.nodeName + " "); document.write("Type of Root node: " + root.nodeType + " "); book1 = root.childNodes.item(0); authors = book1.getElementsByTagName("author"); document.write("Number of authors: " + authors.length + " "); author2 = authors.item(1); document.write("Name of second author: " + author2.childNodes.item(0).data);} DOM Example DOM Example var doc, root, book1, authors, author2; doc = new ActiveXObject("Microsoft.XMLDOM"); doc.async = false; doc.load("books.xml"); if (doc.parseError != 0) alert(doc.parseError.reason); else { root = doc.documentElement; document.write("Name of Root node: " + root.nodeName + " "); document.write("Type of Root node: " + root.nodeType + " "); book1 = root.childNodes.item(0); authors = book1.getElementsByTagName("author"); document.write("Number of authors: " + authors.length + " "); author2 = authors.item(1); document.write("Name of second author: " + author2.childNodes.item(0).data);}

SAX - Simple API for XML Docu- ment DTD Application endDocument startDocument endElement startElement Parser

SAX - Simple API for XML Event-driven parsing model "Don't call the DOM, the parser calls you." Developed by the members of the XML-DEV Mailing List Released on May 11, 1998 Supported by many parsers but Ælfred is the saxon king.

Procedure DOM  Creating a parser instance  Parsing the whole document  Processing the DOM tree SAX  Creating a parser instance  Registrating event handlers with the parser  Parser calls the event handler during parsing

Namespace Support <orderxmlns=" xmlns:bk=" xmlns:cust=" >... XML Handbook

Access to Qualified Elements Node "book" bk:book bk book Interface "Node" DOM Level 2 Method nodeName namespaceURI prefix localName qName uri localName SAX 2.0 startElement

Generation of Data Structures DTD / Schema 'yacht' Generation 01yacht 05name 05details 10type Class Processing Mona Lisa Any text describing this yacht 147 GULFSTAR 55 ength> yacht 05VENTANA 05details 10GULFSTAR 55 Object

Summary To avoid expensive text processing, applications use an XML parser that creates a DOM tree of a document. The DOM provides a standardized API to access the content of documents and to manipulate them. Alternatively or additionally, applications can work event-based using the SAX interface, which is provided by many parsers.