3/29/2001 O'Reilly Java 2001 1 Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
Advertisements

The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc.
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
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.
SDPL 2003Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
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.
JAXP Transformation Package and Xalan Extensions 黃立昇
Parsing XML into programming languages JAXP, DOM, SAX, JDOM/DOM4J, Xerces, Xalan, JAXB.
SAP Web AS – Basics of XML and XSLT Sam Tingleff Technology Product Management, SAP Labs.
31 Signs That Technology Has Taken Over Your Life: #6. When you go into a computer store, you eavesdrop on a salesperson talking with customers -- and.
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.
Implementation of One Stop Search by XSLT By Dave Low University of Hong Kong 9-Dec-2003.
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.
Introduction to XML Extensible Markup Language
XML: Java Dr Andy Evans. Java and XML Couple of things we might want to do: Parse/write data as XML. Load and save objects as XML. We’ll mainly discuss.
17 Apr 2002 XML Programming: TrAX Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
Technical Track Session XML Techie Tools Tim Bornholt.
SDPL : (XML APIs) JAXP1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –In Java: through JAXP –An overview of.
XML on the Web: is it still relevant? O'Neil D. Delpratt.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
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.
SDPL 2003Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
1 Document Object Model (DOM) MV4920 – XML 24 September 2001 Simon R. Goerger MAJ, US Army
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
XML and its applications: 4. Processing XML using PHP.
SDPL 2004Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
1 JAXP & XSLT. Objectives 2  TrAX API  Transforming XML Documents  Workshops.
1 Java and XML Modified from presentation by: Barry Burd Drew University Portions © 2002 Hungry Minds, Inc.
EXtensible Markup Language (XML) James Atlas July 15, 2008.
SDPL 2002Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
SDPL 20113: XML APIs and SAX1 3. XML Processor APIs n How can (Java) applications manipulate structured (XML) documents? –An overview of XML processor.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
SAX. What is SAX SAX 1.0 was released on May 11, SAX is a common, event-based API for parsing XML documents Primarily a Java API but there implementations.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
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.
XML Grammar and Parser for WSOL Kruti Patel, Vladimir Tosic, Bernard Pagurek Network Management & Artificial Intelligence Lab Department of Systems & Computer.
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.
SAX2 and DOM2 Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
COSC617 Project XML Tools Mark Liu Sanjay Srivastava Junping Zhang.
Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
SDPL 20063: XML Processor Interfaces1 3. XML Processor APIs n How can (Java) applications manipulate structured (XML) documents? –An overview of XML processor.
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.
SDPL 2001Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How applications can manipulate structured documents? –An overview of document parser.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
1 Validation SAX-DOM. Objectives 2  Schema Validation Framework  XML Validation After Transformation  Workshops.
Java API for XML Processing
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
{ XML Technologies } BY: DR. M’HAMED MATAOUI
Unit 4 Representing Web Data: XML
Parsing XML into programming languages
Using XML Tools CS551 – Fall 2001.
Java/XML.
Chapter 7 Representing Web Data: XML
Java API for XML Processing
A parser for XML Documents
Presentation transcript:

3/29/2001 O'Reilly Java Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems

3/29/2001 O'Reilly Java Introduction JAXP 1.0 emerged to fill deficiencies in existing industry standards: SAX 1.0 and DOM Level 1. Examples: Bootstrapping a DOM tree Controlling parser validation Since JAXP 1.0: Industry standards changed: SAX 2.0, DOM Level 2 JAXP expanded to satisfy more needs: XSLT

3/29/2001 O'Reilly Java JAXP 1.1 JAXP enables apps to parse and transform XML documents Allows apps to be independent of a particular implementation Augments existing SAX and DOM API standards

3/29/2001 O'Reilly Java New Features in 1.1 Name change from “Parsing” to “Processing” Support for XSLT 1.0 based on TrAX (Transformation API for XML) Parsing API updated to SAX 2.0 and DOM Level 2 Improved scheme to locate pluggable implementations

3/29/2001 O'Reilly Java Application Usage 1.Parsing using SAX Parsing using DOM Level 2 3.Transformation using XSLT

3/29/2001 O'Reilly Java JAXP 1.1 Components SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* JAXP API javax.xml.transform.* New in 1.1

3/29/2001 O'Reilly Java ) SAX Parsing Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* SAX Parsing App javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java ) DOM Parsing Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* DOM Parsing App javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java ) Transform Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* Transform Application javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java ) Parsing using SAX 2.0 Application supplies a SAX ContentHandler to parser Application tells parser to start parsing a document Parser calls methods in the ContentHandler that application previously supplied during parse

3/29/2001 O'Reilly Java SAX 2.0 Parsing XML Document SAX ContentHandler Event Callbacks Application Supplied Input Parser

3/29/2001 O'Reilly Java SAX ContentHandler public interface ContentHandler { void startElement(namespaceURI, localName, qName, atts); void endElement(namespaceURI, localName, qName); void characters(ch[], start, length);... }

3/29/2001 O'Reilly Java Example: SAX2 Application 1. XMLReader xmlReader = create SAX2 XMLReader instance 2. xmlReader.setContentHandler(myContentHandler); 3. xmlReader.parse(myInputSource);

3/29/2001 O'Reilly Java Create XMLReader SAXParserFactory spf = SAXParserFactory.newInstance(); // Change namespaces feature to SAX2 default spf.setNamespaceAware(true); // Create SAX XMLReader w/ SAX2 default features XMLReader xmlReader = spf.newSAXParser().getXMLReader(); // Use xmlReader as you would normally...

3/29/2001 O'Reilly Java SAX Parsing Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* SAX Parsing App javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java Changing the Implementation Define a system property: javax.xml.parsers.SAXParserFactory $JAVA_HOME/jre/lib/jaxp.properties file Jar Service Provider META-INF/services/javax.xml.parsers.SAXParserFactory Platform default (fallback)

3/29/2001 O'Reilly Java Jar Service Provider Jar file may contain a resource file called …/javax.xml.parsers.SAXParserFactory containing the name of a concrete class to instantiate JAXP static SAXParserFactory.newInstance() method searches classpath for resource and instantiates specified concrete class

3/29/2001 O'Reilly Java Examples: Using a Particular Implementation With Java 2 version 1.3 To use Xerces, use classpath = xerces.jar (contains all classes) To use Crimson, use classpath = jaxp.jar (contains javax.xml.*) crimson.jar (contains sax, dom) You get Xerces, if classpath = jaxp.jar xerces.jar crimson.jar (Jar file names correct as of Feb 2001)

3/29/2001 O'Reilly Java ) DOM Parsing Example Application gives DOM builder an XML document to parse Builder returns with a DOM Document object representing the DOM “tree”

3/29/2001 O'Reilly Java DOM Parsing XML Document Input Parser Output Tree

3/29/2001 O'Reilly Java JAXP Adds to DOM Level 2 Method to “Load” a DOM Document object from an XML document* Methods to control parser behavior such as validation and error handling* Provides pluggable DOM parser implementation * Proposed for Level 3

3/29/2001 O'Reilly Java JAXP DOM Example // Get platform default implementation DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Set options dbf.setNamespaceAware(true); dbf.setValidating(true); // Create new builder DocumentBuilder db = dbf.newDocumentBuilder(); db.setErrorHandler(myErrorHandler); Document doc = db.parse(“ // Use doc with usual DOM methods...

3/29/2001 O'Reilly Java DOM Parsing Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* DOM Parsing App javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java JAXP DocumentBuilderFactory Has same pluggability mechanism as SAXParserFactory does

3/29/2001 O'Reilly Java ) Transformation Using XSLT Major new feature Enables transformation of one XML document into another XML document using XSLT 1.0 API based on TrAX, Transformation API for XML, initiated by Scott Boag, Michael Kay, and others. Incorporated into JAXP version 1.1. Provides pluggable Transform implementation similar to parsing

3/29/2001 O'Reilly Java Transformation Diagram XSLT Stylesheet XSLT Processor Input Transformer instance XML Document Input XML Document Output Source Result

3/29/2001 O'Reilly Java Transformation Example Create Transform instance from XSLT stylesheet Use the Transform instance to transform the source document into a result document by calling: Transform.transform(Source, Result)

3/29/2001 O'Reilly Java Transform Arguments Specialized implementations of generic Source and Result interfaces are in javax.xml.transform.stream javax.xml.transform.sax javax.xml.transform.dom Different combinations of Source and Result can be passed to transform() method Examples: StreamSource, DOMSource, SAXResult, StreamResult

3/29/2001 O'Reilly Java Transform Example Code // Get concrete implementation TransformFactory tf = TransformFactory.newInstance(); // Create a transformer for a particular stylesheet Transformer transformer = tf.newTransformer( new StreamSource(stylesheet)); // Transform input XML doc to System.out transformer.transform(new StreamSource(sourceId), new StreamResult(System.out));

3/29/2001 O'Reilly Java Transform Application SAX org.xml.sax.* DOM org.w3c.dom.* javax.xml.parsing.* Transform Application javax.xml.transform.* JAXP API

3/29/2001 O'Reilly Java Example XSLT Stylesheet <xsl:stylesheet xmlns:xsl=" version="1.0"> Stock Quotes body { background-color: white; }

3/29/2001 O'Reilly Java Example XSLT Stylesheet (cont) Stock Quotes

3/29/2001 O'Reilly Java Example: Output a DOM Tree How do I output a DOM tree as XML? Future: a requirement of DOM Level 3 Can use a JAXP 1.1 transform to do this Create an identity Transformer Transform DOMSource to StreamResult: identity.transform(domSource, streamResult)

3/29/2001 O'Reilly Java Demonstration Transform stock data in some XML format into a document which can be viewed in an HTML browser. Use 2 transforms: Stock data to SVG Stock data to XHTML Rasterize SVG into image

3/29/2001 O'Reilly Java Stock Data Demo XML Stock Data XStock To SVG Rasterizer PNG Image Graph Of Data XStock To XHTML Doc HTML Browser href Input Output (binary) Output SVG

3/29/2001 O'Reilly Java References My web page: Apache XML projects: xml.apache.orgxml.apache.org SAX: DOM: JAXP specs, RI: java.sun.com/xmljava.sun.com/xml SAXON: users.iclway.co.uk/mhkay/saxonusers.iclway.co.uk/mhkay/saxon

3/29/2001 O'Reilly Java Questions