1 JAXP & XSLT. Objectives 2  TrAX API  Transforming XML Documents  Workshops.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advanced XSLT. Branching in XSLT XSLT is functional programming –The program evaluates a function –The function transforms one structure into another.
Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.
CG0119 Web Database Systems Parsing XML: using SimpleXML & XSLT.
XML: Extensible Markup Language
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XML: Managing Data Exchange Stylesheets. Lesson Contents CSS The basic XSL file XSL transforms Templates Sort Numbering Parameters and Variables Datatypes.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
1 CP3024 Lecture 9 XML revisited, XSL, XSLT, XPath, XSL Formatting Objects.
XML Parsing Using Java APIs AIP Independence project Fall 2010.
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.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
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.
JAXP Transformation Package and Xalan Extensions 黃立昇
XSL Unit 6 November 2. XSL –eXtensible Stylesheet Language –Basically a stylesheet for XML documents XSL has three parts: –XSLT –XPath –XSL-FO.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
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.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
17 Apr 2002 XML Programming: TrAX Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
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.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
ECA 228 Internet/Intranet Design I Intro to XSL. ECA 228 Internet/Intranet Design I XSL basics W3C standards for stylesheets – CSS – XSL: Extensible Markup.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
IS432 Semi-Structured Data Lecture 5: XSLT Dr. Gamal Al-Shorbagy.
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
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.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
3/29/2001 O'Reilly Java Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
Declaratively Producing Data Mash-ups Sudarshan Murthy 1, David Maier 2 1 Applied Research, Wipro Technologies 2 Department of Computer Science, Portland.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
XML and Database.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved.2 Revised by Dr. T. Tran for CSI3140.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
1 JAXP & XPATH. Objectives 2  XPath  JAXP Processing of XPath  Workshops.
Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.
Unit 3 — Advanced Internet Technologies Lesson 11 — Introduction to XSL.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Creating a Java Application and Applet
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Lab 04-2 Objectives:  Understand what a file is.  Learn how to use the File class  Learn how to use the Scanner class to read from files  Learn about.
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.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
1 Introduction SAX. Objectives 2  Simple API for XML  Parsing an XML Document  Parsing Contents  Parsing Attributes  Processing Instructions  Skipped.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Unit 4 Representing Web Data: XML
DOM Robin Burke ECT 360.
Java/XML.
Chapter 7 Representing Web Data: XML
Presentation transcript:

1 JAXP & XSLT

Objectives 2  TrAX API  Transforming XML Documents  Workshops

TrAX API  XML Transformation  Transforms the XML document into another XML document as output, which fulfills some particular objective.  There are two unique cases  XML to XML  The output is always an XML document.  It is mostly used when you need to create XML pipelines from XML chain. The XML pipeline is created when XML transformations are connected to each other.  The XML chain is the collection of XML documents which bind with each other.  XML to Data  The output is always a byte stream.  Comes under this case because the HTML document contains a stream of bytes  TrAX APIs  Is an API, which provides a general transformation model for converting XML documents

TrAX API packages PackagesDescriptions javax.xml.transform - Implements the generic APIs for transformation instructions and executing the transformation, starting from source to destination. - The interfaces present in this package are ErrorListener, Result, Source, SourceLocator, Templates, URIResolver. - The classes present in this package are OutputKeys, Transformer, TransformerFactory javax.xml.transform.stream - Implements streams and URI specific transformation APIs. - The classes present in this package are StreamResult, StreamSource javax.xml.transform.dom - Implements DOM-related transformation APIs. - The interface present in this package is DOMLocator javax.xml.transform.sax - Implements SAX-related transformation APIs. - The interfaces present in this package are TemplateHandler, TransformerHandler

XSLT Stylesheets  Is a language used for transforming XML documents into XHTML documents for Web pages.  Uses XPath language to navigate between XML documents and XHTML documents.  Defines the source documents, which will be matched with a predefined set of templates in transformation process. If XSLT gets the same document, it transforms the matching part of the source document into the output document. XML Book titleauthorprice XSLT html headbody h1h2p text... Serialization abc...

Transformer class  Is used to transform a XML source tree into a result tree that is a well formed xml output document MethodsDescriptions transform - public abstract void transform(Source xmlSource, Result outputTarget) throws TranformerException - Is used to process the source tree into the result tree setParameter - public abstract void setParameter(String name, Object value) - Is used to add parameter for the transformation process. - The parameters help in transformation the document getParameter - public abstract Object getParameter(String name) - Is used to get a parameter, which explicitly set using the setParameter() or setParameters() method clearParameters - public abstract void clearParameters() - Is used to clear all parameters set with the setParameter method setURIResolver - public abstract void setURIResolver(URIResolver resolver) - Sets an object, which is used to resolve the URIs getURIResolver - public abstract URIResolver getURIResolver() - Gets an object, which is used to resolve the URIs

Transformer class (cont) MethodsDescriptions setOutputProperties - public abstract void setOutputProperties(Properties prop) throws IllegalArgumentException - Sets the output properties for transformation getOutputProperties - public abstract Properties getOutputProperties() - Gets a copy of the output properties for transformation. setOutputProperty - public abstract void setOutputProperties(String name, String value) throws IllegalArgumentException - Sets an output property, which makes effects for the transformation getOutputProperty - public abstract String getOutputProperties(String name) throws IllegalArgumentException - Gets an output property, which makes effects for the transformation setErrorListener - public abstract void setErrorListener(ErrorListener listener) throws IllegalArgumentException - Sets the error event listener for the transformation getErrorListener - public abstract ErrorListener getErrorListener() - Gets the error event listener for the transformation

TransformerFactory class MethodsDescriptions newInstance - public static TranformerFactory newInstance() throws TransformerFactoryConfigurationError - Gets a new instance of a TransformerFactory newTransformer - public abstract Transformer newTransformer(Source source) throws TransformerConfigurationException - Is used to convert the source object into a Transformer object. This object should not be used in multiple threads newTemplates - public abstract Templates newTemplates(Source source) throws TransformerConfigurationException - Is used to convert the source object into a complied representation of source template setURIResolver - public abstract void setURIResolver(URIResolver resolver) - Is used to set the object that is to be used by default throughout the transformation getURIResolver - public abstract URIResolver getURIResolver() - Is used to get the object that is to be used by default throughout the transformation

TransformerFactory class (cont) MethodsDescriptions getFeature - public abstract Boolean getFeature(String name) - Is used to search the value of a parameter setAttribute - public abstract void setAttribute(String name, Object value) throws IllegalArgumentException - Permits the user to set the values of specific attributes getAttribute - public abstract Object getAttribute(String name) throws IllegalArgumentException - Permits the user to get the values of specific attributes setErrorListener - public abstract void setErrorListener(ErrorListener listener) throws IllegalArgumentException - Is used to set the error event listener getErrorListener - public abstract ErrorListener getErrorListener() - Is used to get the error event listener

OutputKeys 1.public static void main(String[] args) throws Exception { 2.TransformerFactory tf = transformerFactory.newInstance();TransformerFactory 3.Transformer t = tf.newTransformer();Transformer 4.t.setOutputProperty(OutputKeys.INDENT, "yes"); 5.t.setOutputProperty ("{ "4"); 6.t.setOutputProperty(OutputKeys.METHOD, "xml"); 7.Source source = new SAXSource(new SerializeSax(), new InputSource());Source 8.Result result = new StreamResult(new OutputStreamWriter(System.out));Result 9.t.transform(source, result); 10. } 10

Source & Result interface  Source Interface  Result Interface MethodsDescriptions setSystemId - public void setSystemId(String systemId) - Is used to set the system identifier for Source getSystemId - public String getSystemId() - Is used to get the system identifier, which previously set with setSystemId() MethodsDescriptions setSystemId - public void setSystemId(String systemId) - Is used to set the system identifier for Result class getSystemId - public String getSystemId() - Is used to get the system identifier, which previously set with setSystemId() method

Template interface  The object, which implements the Template interface, is the runtime result of transformation instructions.  Can be called from multiple threads for a particular instance. MethodsDescriptions newTransformer - public Transformer newTransformer() throws TransformerConfigurationException - Is used to create a new transformation object getOutputProperties - public Properties getOutputProperties () - Is used to get the static properties for xsl:output. The xsl:output is used to define the format of the output

Transforming XML documents

TransformerFactory  To create transformer and Template objects, an instance of the TransformerFactory class is used.  Features of TransformerFactory are  The system property of TransformerFactory is always set as javax.xml.transform. TransformerFactory.  The default property is used by the TransformerFactory class if the property is not set manually.  The newInstance() method is used by TransformerFactory class to create instance.  A TransformerFactory never perform multiple operations at a time  A transformation always has a source and a result.

Transformer  An instance of transformer class is used to change a source tree into a result tree in an XML document.  The TransformerFactory.newTransformer() method is used to get the instances of Transformer class  To process the XML data from other sources and write the outputs, the instance of Transformer class is used.  The objects of Transformer class functions correctly during simultaneous execution by multiple threads.  Some methods used by this class are clearParameters() and getURIResolver().

Example public class TraxEx { public static void main (String[] args) { if(args.length<=0){ System.out.println("Usage: java TraxEx xsltFile xmlFile SortedOrders.html"); return; } try { TransformerFactory tf = TransformerFactory.newInstance (); Transformer trans = tf.newTransformer (new StreamSource(args[0])); trans.transform (new StreamSource(args[1]), new StreamResult(new FileOutputStream(args[2]))); System.out.println("File SortedOrders.html created in current folder"); }catch(Exception e){ e.printStackTrace (); }

Example (cont)  XSLT file Customer Item Quantity Price

Example (cont)  XML file Chris Color TV David DVD Player Mitchell Washing Machine

Example (cont)

WORKSHOP ACTIVITIES Building the console Java application using XSLT to transform the XML document combining with XSLT file to HTML file.