Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.

Slides:



Advertisements
Similar presentations
The Document Object Model
Advertisements

Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 22. Oktober 2009.
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.
XML Parsers By Chongbing Liu. XML Parsers  What is a XML parser?  DOM and SAX parser API  Xerces-J parsers overview  Work with XML parsers (example)
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky.
Lecture 4 Java Interfaces (review of inheritance and abstract classes) The XML DOM Java Examples Homework 3.
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 XML and Data Management XML Processors Hachim Haddouti Al Akhawayn University SSE
Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.
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.
Java API for XML Processing (JAXP) CSE 4/586: Distributed Systems Department of Computer Science and Engineering University at Buffalo, New York Jia Zhao.
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.
SE 5145 – eXtensible Markup Language (XML ) DOM (Document Object Model) (Part I) /Spring, Bahçeşehir University, Istanbul.
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.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
1 XML Data Management 4. Domain Object Model Werner Nutt.
5 Processing XML Parsing XML documents  Document Object Model (DOM)  Simple API for XML (SAX) Class generation Overview.
17 Apr 2002 XML Programming - DOM Andy Clark. DOM Design Premise Derived from browser document model Defined in IDL – Lowest common denominator programming.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
Beginning XML 4th Edition. Chapter 12: Simple API for XML (SAX)
The XML Document Object Model (DOM) Aug’10 – Dec ’10.
Extensible MarkUp Language. AGENDA  OVERVIEW OF XML  DATA TYPE DEFINITION LANGUAGE  XML SCHEMA  XML PARSERS 1) DOM PARSER 2) SAX PARSER 3) JAXB PARSER.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
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.
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.
Consuming eXtensible Markup Language (XML) feeds.
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.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML Study-Session: Part III
Document Object Model DOM. Agenda l Introduction to DOM l Java API for XML Parsing (JAXP) l Installation and setup l Steps for DOM parsing l Example –Representing.
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,
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.
Processing XML with Java
Document Object Model.  The XML DOM (Document Object Model) defines a standard way for accessing and manipulating XML documents.  The DOM presents an.
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.
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
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.
USING ANDROID WITH THE DOM. Slide 2 Lecture Summary DOM concepts SAX vs DOM parsers Parsing HTTP results The Android DOM implementation.
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
Week-9 (Lecture-1) XML DTD (Data Type Document): An XML document with correct syntax is called "Well Formed". An XML document validated against a DTD is.
XML. Contents  Parsing an XML Document  Validating XML Documents.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Parsing XML into programming languages
Java/XML.
Data Modeling II XML Schema & JAXB Marc Dumontier May 4, 2004
More DOM 13-Nov-18.
DOM Document Object Model.
XML Parsers By Chongbing Liu.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
More DOM 28-Nov-18.
DOM 8-Dec-18.
More DOM.
DOM 24-Feb-19.
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
XML Parsers.
WaysInJavaToParseXML
XML and Web Services (II/2546)
Presentation transcript:

Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky

Apache DOM ParserOctober 24, 2002©zwz Overview  org.w3c.dom –Node Document Element Attr Text –NodeList –NamedNodeMap  org.apache.xerces.parsers –DOMParser  Sample Code Segment  Xerces Parser Info

Apache DOM ParserOctober 24, 2002©zwz Overview This is a test “is” “This” “a test” id= “1”

Apache DOM ParserOctober 24, 2002©zwz Overview “is” “This” “a test” id= “1” Document

Apache DOM ParserOctober 24, 2002©zwz Overview “is” “This” “a test” id= “1” Document Element

Apache DOM ParserOctober 24, 2002©zwz Overview “is” “This” “a test” id= “1” Document Element Attr Text

Apache DOM ParserOctober 24, 2002©zwz DOM Interface  Represents XML documents as objects –Extract information –Manipulate XML documents  A set of Interfaces –Defined by w3c –Platform and language-neutral –Must be implemented by classes which contain actual data –The DOM parser: responsible for providing those implementation classes

Apache DOM ParserOctober 24, 2002©zwz DOM Interface Hierarchy  Node –Attr –CharacterData Comment Text –CDATASection –Document –DocumentFragment –DocumentType –Element –Entity –EntityReference –Notation –ProcessingInstruction  DOMImplementation  NamedNodeMap  NodeList

Apache DOM ParserOctober 24, 2002©zwz Interface Node  Represents a single node  The primary datatype for the entire DOM  Methods defined here are available for all sub-interfaces  Methods –Public NodeList getChildNodes() –Public Node getFirstChild() –Public Node getNextSibling() –Public Node getParentNode() –Public NamedNodeMap getAttributes()

Apache DOM ParserOctober 24, 2002©zwz Interface Node (cont’) –Public String getNodeName() –Public String getNodeValue() –Public short getNodeType() –Public Node appendChild(Node newChild) throws DOMException –Public Node removeChild(Node oldChild) throws DOMException

Apache DOM ParserOctober 24, 2002©zwz Interface Document  Represents an entire XML document  Methods –Public Element getDocumentElement() Returns the root element of the document –Public NodeList getElementsByTagName(String tag) Returns a list of nodes with the specified tag name In the order of a preorder traversal of the document

Apache DOM ParserOctober 24, 2002©zwz Interface Element  Represents an element in a document  Methods –Public NodeList getElementsByTagName(String tag) Returns a list of nodes with the specified tag name In the order of a preorder traversal of the document –Public String getTagName() –Public Attr getAttributeNode()

Apache DOM ParserOctober 24, 2002©zwz Interface Attr  Represents an attribute in an Element object  Methods –Public String getName() –Public String getValue() –Public void setValue(String value) throws DOMException

Apache DOM ParserOctober 24, 2002©zwz Interface Text  Represents the textual content of an Element or Attr  Methods –Public String getData() throws DOMException –Public void setData(String data) throws DOMException –Public int getLength() Returns the size of the Text node

Apache DOM ParserOctober 24, 2002©zwz Interface NodeList  Represents a collection of nodes –an ordered collection  Methods –Public Node item(int index) Returns the node with the specified index Note: index starts with 0 –Public int getLength() Returns the size of the node list

Apache DOM ParserOctober 24, 2002©zwz Interface NamedNodeMap  Represents a collection of nodes –Can be accessed by name –Not maintained in any particular order  Methods –Public Node getNamedItem(String name) Returns the node with the specified name –Public Node item(int index) Returns the node with the specified ordinal index Note: index starts with 0 –Public int getLength() Returns the size of the node collection –Public void setNamedItem(Node newNode) throws DOMException

Apache DOM ParserOctober 24, 2002©zwz Class DOMParser  A software library (or software package) –Provides clear APIs for client applications to manipulate XML documents.  Is tree-based –Produces a w3c DOM tree in memory which is called a Document object.  Client applications access or modify the information stored in the original XML document by –Invoking methods on the Document object –Invoking methods on other objects it contains.  Vendors: –Apache, Oracle, IBM, Microsoft, Sun, Tibco

Apache DOM ParserOctober 24, 2002©zwz DOMParser (cont’)  Constructor: –Public DOMParser() Use DTD/Schema parser configuration  Methods –Public void parse(String systemId) throws SAXException and IOException Build a DOM tree if successful –Public void parse(InputSource is) throws SAXException and IOException Build a DOM tree if successful –Public Document getDocument() Return a Document object

Apache DOM ParserOctober 24, 2002©zwz DOMParser (cont’) –void setFeature(String featureId, boolean state) Throws SAXNotRecognizedException and SAXNotSupportedException Set the state of the feature in the SAX2 parser –void setProperty(String propertyId, Object value) Throws SAXNotRecognizedException and SAXNotSupportedException Set the value of the property in the SAX2 parser schemaLocationhttp://apache.org/xml/properties/schema/external- schemaLocation

Apache DOM ParserOctober 24, 2002©zwz DOMParser (cont’) –Protected void setValidation(boolean validation) Throws SAXNotRecognizedException and SAXNotSupportedException Set whether the parser validates (by default, against DTD) Equivalent to setFeature() –Feature ID: –Protected void setValidationSchema(boolean schema) Throws SAXNotRecognizedException and SAXNotSupportedException Set schema support on/off Equivalent to setFeature() –Feature ID:

Apache DOM ParserOctober 24, 2002©zwz Sample Code Segment DOMParser parser = new DOMParser();// Create a Xerces DOM Parser parser.setFeature(“ true); // Set the feature for validation against DTD /* Prepare the SystemId for the XML document here … */ parser.parse(SystemId);//Parse the input XML document Document doc = parser.getDocument();//Obtain the Document object Element root = doc.getDocumentElement();//Obtain the root element NodeList nl = doc.getElementsByTagName(“person");//Get the Node List by name int len = nl.getLength();//Get the length of the NodeList for (int i = 0; i < len; i++) { Node node = (Node) nl.item(i);//Get the Node by index if (node.hasChildNodes()) { //Do something for this Node’s children Node firstChild = (Node) node.getFirstChild(); … }

Apache DOM ParserOctober 24, 2002©zwz Xerces Parser Info  Apache Xerces Parser API:  Feature IDs:  Property IDs:  Location for Xerces Parser in cslab machine: /usr/local/xml-xerces2  Be sure to include the following packages in your java source: –org.apache.xerces.parsers.DOMParser –org.xml.sax.helpers.* –org.xml.sax.* –org.w3c.dom.* –Others maybe