More DOM 28-Nov-18.

Slides:



Advertisements
Similar presentations
The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc.
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
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.
SDPL 2002Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
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.
Tomcat Java and XML. Announcements  Final homework assigned Wednesday  Two week deadline  Will cover servlets + JAXP.
Parsing XML into programming languages JAXP, DOM, SAX, JDOM/DOM4J, Xerces, Xalan, JAXB.
Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.
21-Jun-15 SAX (Abbreviated). 2 XML Parsers SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard.
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.
26-Jun-15 SAX. 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.
27-Jun-15 XOM. XOM Design Principles XOM (XML Object Model) is yet another XML parser, by textbook author Elliott Rusty Harold The goals of XOM, in order,
MC365 XML Parsers. Today We Will Cover: An overview of the Java API’s used for XML processing Creating an XML document in Java Parsing an XML document.
JAX- Java APIs for XML by J. Pearce. Some XML Standards Basic –SAX (sequential access parser) –DOM (random access parser) –XSL (XSLT, XPATH) –DTD Schema.
Apache DOM Parser©zwzOctober 24, 2002 Wenzhong Zhao Department of Computer Science The University of Kentucky.
Xpath Sources:
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.
17 Apr 2002 XML Programming: JAXP Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
The Joy of SAX (and DOM, and JDOM…) Bill MacCartney 11 October 2004.
1 XML Data Management 4. Domain Object Model Werner Nutt.
JS: Document Object Model (DOM)
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
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.
3/29/2001 O'Reilly Java Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems.
1 Java and XML Modified from presentation by: Barry Burd Drew University Portions © 2002 Hungry Minds, Inc.
The XML Document Object Model (DOM) Aug’10 – Dec ’10.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
Java API for XML Processing (JAXP) Dr. Rebhi S. Baraka Advanced Topics in Information Technology (SICT 4310) Department of Computer.
April 30, ICE 1341 – Programming Languages (Lecture #18) In-Young Ko Programming Languages (ICE 1341) Lecture #18 Programming Languages (ICE 1341)
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.
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,
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.
XML. DCS – SWC 2 Data vs. Information We often use the terms data and information interchangeably More precisely, data is some ”value” of a certain type,
Schema Data Processing
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
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.
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.
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
XML. Contents  Parsing an XML Document  Validating XML Documents.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Parsing XML into programming languages
Java/XML.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
More DOM 13-Nov-18.
DOM Document Object Model.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Java API for XML Processing
DOM 8-Dec-18.
WaysInJavaToParseXML
More DOM.
DOM 24-Feb-19.
XML DOM and CSS Instructors: Geoffrey Fox and Bryan Carpenter
XML document processing in Java using XPath and XSLT
WaysInJavaToParseXML
Presentation transcript:

More DOM 28-Nov-18

Manipulating DOM trees DOM, unlike SAX, gives you the ability to create and modify XML trees There are a few roadblocks along the way Practically everything in the JAXP implementation is an interface, with a few abstract classes Interfaces, such as Node, don’t have constructors; this makes it hard to get started Since DOM was designed to be applicable from a number of languages, many things are not done “the Java way” Once you get past these problems, the individual methods are pretty straightforward Even with straightforward methods, working with trees is seldom simple

Overview There are three basic kinds of operations: Creating a new DOM Modifying the structure of a DOM Modifying the content of a DOM Creating a new DOM requires a few extra methods just to get started Afterwards, you can “grow” the DOM by modifying its structure and content

Creating a DOM import javax.xml.parsers.*; import org.w3c.dom.Document; try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); } catch (ParserConfigurationException e) { ... }

The rest of the methods Most of the other methods are either instance methods of a Document object, or are inherited from Node A few are from Attr, Text, Entity, and so on Almost all of these methods may throw a DOMException I’ll just go through some of the more important methods briefly The details can be looked up in the API if needed

Creating structure The following are instance methods of Document: public Element createElement(String tagName) public Element createElementNS(String namespaceURI, String qualifiedName) public Attr createAttribute(String name) public Attr createAttributeNS(String namespaceURI, String qualifiedName) public ProcessingInstruction createProcessingInstruction (String target, String data) public EntityReference createEntityReference(String name) The above may all throw a DOMException public Text createTextNode(String data) public Comment createComment(String data)

Methods inherited from Node public Node appendChild(Node newChild) public Node insertBefore(Node newChild, Node refChild) public Node removeChild(Node oldChild) public Node replaceChild(Node newChild, Node oldChild) setNodeValue(String nodeValue) What this does depends on the type of node public void setPrefix(String prefix) public void normalize() Combines adjacent TextNodes

Methods of Element public void setAttribute(String name, String value) public Attr setAttributeNode(Attr newAttr) public void setAttributeNodeNS(String namespaceURI, String qualifiedName, String value) public Attr setAttributeNodeNS(Attr newAttr) public void removeAttribute(String name) public void removeAttributeNS(String namespaceURI, String localName) public Attr removeAttributeNode(Attr oldAttr)

Method of Attr public void setValue(String value) This is the only method that modifies an Attr; the rest just get information

Writing out the DOM as XML There are no Java-supplied methods for writing out a DOM as XML Writing out a DOM is conceptually simple—it’s just a tree walk However, there are a lot of details—various node types and so on—so doing a good job isn’t complicated, but it is lengthy

The End