Sheet 1XML Technology in E-Commerce 2001 Lecture 7
XML Technology in E-Commerce
Lecture 7
XSL Formatting Objects, Java Data Binding
Sheet 2XML Technology in E-Commerce 2001 Lecture 7
• XSL Formatting Objects– Formatting Objects as a part of XSL suite;
– Page Model;
– Creating Templates;
– Creating Blocks and Inline elements;
• Java Data Binding– Purpose of Data Binding: translation of XML
documents to application objects;
– Examples:• Castor;
• Jato;
Lecture Outline
Sheet 3XML Technology in E-Commerce 2001 Lecture 7
XML
XML Namespaces
XPath
XPointerXSLT
XLink
XML Schema
XML Languages
Parser
DOMSAX
Software Application
Overview
XSL FO
Data Binding Facility
Sheet 4XML Technology in E-Commerce 2001 Lecture 7
Rendering XML• Transformation to a document suitable for presentation
on a device like display, aural device, etc;
• The result tree has a formatting semantics expressed in terms of formatting objects;
XMLDocument
CSSStylesheet Browser
Transformation(XSLT)
FODocument
HTML
WML
Sheet 5XML Technology in E-Commerce 2001 Lecture 7
Formatting Objects• After an XSLT transformation the result tree can
contain nodes that are formatting objects;• Formatting objects correspond to typographic
abstractions like page, paragraph, table;• Finer control on the presentation is provided
through the properties of the formatting objects;• XSL FO provides XML vocabulary to specify the
presentation in terms of formatting objects and properties;
Sheet 6XML Technology in E-Commerce 2001 Lecture 7
DemoConverting FO Tree to PDF
• Demo - Deitel 13.3, fig. 13.2, page 356;• Tools:
– Java 2;
– Apache FOP tool (http://xml.apache.org/fop/);
• Demo files:– welcome.fo;
– welcome.pdf;
Sheet 7XML Technology in E-Commerce 2001 Lecture 7
Region-before
Region-after
Reg
ion-
star
t
Reg
ion-
end
Region-body
Page Model
• Simplified page and its regions used in structures that contain formatting objects
Page
Sheet 8XML Technology in E-Commerce 2001 Lecture 7
Setting Up Page Templates<fo:root xmlns:fo = "http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name = "layout1"
page-height = "4in">
…………………………………………………….</fo:root>
• layout-master-set: defines page templates that can be used for page generation;
• simple-page-master: used for the generation of pages. The pages come from the page-sequence element;
Sheet 9XML Technology in E-Commerce 2001 Lecture 7
Setting Up Page Regions
<fo:simple-page-master master-name = "layout1"
page-height = "4in">
<fo:region-body margin-top = "1in"
margin-bottom = "1in" margin-left = "1.5in"
margin-right = "1.5in"/>
<fo:region-before extent = "1in" margin-top = "0.2in"
margin-bottom = "0.2in" margin-left = "0.2in"
margin-right = "0.2in"/>
</fo:simple-page-master>
Sheet 10XML Technology in E-Commerce 2001 Lecture 7
Describing the Page Content
<fo:page-sequence master-name = "run">
<fo:static-content flow-name = "xsl-region-before">
<fo:block font-size = "10pt" line-height = "12pt"
font-family = "sans-serif">
page <fo:page-number/>
</fo:block>
</fo:static-content>
……………………………………….
static-content element causes page numbers to be included in each page header;
Sheet 11XML Technology in E-Commerce 2001 Lecture 7
Creating Paragraphs and Inline elements
<fo:flow flow-name = "xsl-region-body">
<fo:block font-size = "36pt"
font-family = "sans-serif" font-weight = "bold"
space-after.optimum = "24pt" color = "blue"
text-align = "center">Welcome!
</fo:block>
……………………………………………………..
<fo:block font-size = "12pt"
font-family = "sans-serif" line-height = "14pt"
space-after.optimum = "12pt">Deitel & Associates,
Inc. is a member of the
<fo:inline-sequence font-weight = "bold">World
Wide Web</fo:inline-sequence>
Consortium.
</fo:block>
block elements create paragraphs
inline element definesdifferent formattingfor a portion of text ina paragraph
Sheet 12XML Technology in E-Commerce 2001 Lecture 7
DemoXSLT Transformation to FO Document
• Demo - Deitel 13.3, fig. 13.5, page 361;• Tools:
– Java 2;
– XML Spy with XSLT processor;
– Apache FOP tool (http://xml.apache.org/fop/);
• Demo files:– letter.xml;
– letter.xsl;
Sheet 13XML Technology in E-Commerce 2001 Lecture 7
Summary on Formatting Objects
Read: Deitel 13
Assignment: Deitel Ex 13.3
• Part of XSL Suite;• XML application that provides vocabulary for
specifying formatting suitable for print media and aural devices ;
• Apache FOP tool allows easy generation of PDF files from XML documents;
Sheet 14XML Technology in E-Commerce 2001 Lecture 7
• XSL Formatting Objects– Formatting Objects as a part of XSL suite;
– Page Model;
– Creating Templates;
– Creating Blocks and Inline elements;
• Java Data Binding– Purpose of Data Binding: translation of XML
documents to application objects;
– Examples:• Castor;
• Jato;
Lecture Outline
Sheet 15XML Technology in E-Commerce 2001 Lecture 7
XML Processing
XML Parser
DOMSAX
Software Application
XML Document
General Schema for XML Processing:
• Software application recognizes the markups in the XML doc;
• The application is bound to a low-level APIs (SAX, DOM);
• Dependence on the document format. Navigation through the document structure is rigidly encoded in the application;
Sheet 16XML Technology in E-Commerce 2001 Lecture 7
Data Access• Example (simple address):<address>
<street>Baker Street 221b</street>
<city>London</city>
</address>
• Having the address element, obtaining the street through DOM is:
Node str=address.getFirstChild();
String street=str.getFirstChild().getNodeValue();
• But if we have the XML converted to an application
object address, the previous could be:
String street=address.getStreet();
Sheet 17XML Technology in E-Commerce 2001 Lecture 7
The Idea behind the Data Binding
XML Parser
DOMSAX
Software Application
XML Document
InterpreterMapping
Rules
Application Objects
• The application logic doesn’t contain code for XML data access;
• Conversion from XML to application objects is done by an Interpreter on the base of Mapping Rules. This process is called unmarshalling;
• The process of serialization of a set of objects to XML document is called marshalling;
Sheet 18XML Technology in E-Commerce 2001 Lecture 7
Data Binding
Schema(DTD or XML Schema)
XML Document
Classes
Objects
Compile
Unmarshal
Marshal
Instance ofConforms to
Functionality of Data Binding Facility
Sheet 19XML Technology in E-Commerce 2001 Lecture 7
Data Binding
• Every data binding implementation has to provide answer to two questions:– How to convert a schema to a hierarchy of
classes;
– What are the rules for mapping from and to XML and how they are represented;
• Two data binding implementations:– Castor (http://castor.exolab.org/);
– Jato (www.krumel.com/jato);
Sheet 20XML Technology in E-Commerce 2001 Lecture 7
Castor
• Java-based data binding framework that supports marshalling and unmarshalling;
• Generates source of the classes on the base of XML Schema;
• Can use already existing application classes;
• Uses class and field descriptors to represent the mapping information;
• Based on Java Beans component model;
Sheet 21XML Technology in E-Commerce 2001 Lecture 7
Class Descriptors• Mapping information is represented from
the Java object’s point of view;• Description is made on the base of Java
Beans name conventions;• Description takes the form of an XML
document;• Descriptors specify the mapping of classes
and fields to XML elements and attributes;• Example files for a simple order -
order.xml, MyOrder.java, Item.java, mapping.xml;
Sheet 22XML Technology in E-Commerce 2001 Lecture 7
Jato
• Library for transforming XML to Java and Java to XML;
• JavaBeans naming convention support;• The correspondence between XML
elements and attributes and Java objects is specified in Jato transformation XML document;
• Transformation document is written in Jato script;
Sheet 23XML Technology in E-Commerce 2001 Lecture 7
Jato Transformations
Jato Script XML Doc
Jato Interpreter
Object Helper
Jato Script XML Helper
XML Generator
XML
Objects
XML to Java Java to XML
Sheet 24XML Technology in E-Commerce 2001 Lecture 7
XML to Java Example<system-properties>
<property name="awt.toolkit" value="sun.awt.windows.WToolkit" />
</system-properties>
We want to create an object instance of java.util.Properties class:<Jato:java-defs xmlns:Jato='http://www.krumel.com/jato' >
<Jato:import>java.util.*</Jato:import>
<Jato:translate elt='system-properties'>
<Jato:object class='Properties' publish='props’>
<Jato:on-elt name='property' action='Jato:invoke’ method='setProperty'>
<Jato:param type='string' path='@name'/>
<Jato:param type='string' path='@value'/>
</Jato:on-elt>
</Jato:object>
</Jato:translate>
</Jato:java-defs>
Sheet 25XML Technology in E-Commerce 2001 Lecture 7
Summary on Data Binding
• Frameworks for translating XML to a set of application objects and objects to XML document;
• Usually uses Java language and JavaBeans naming conventions;
• Correspondence between XML and objects is specified in a separate descriptor document by using declarative syntax;
• Generation of classes on the base of DTD/XML Schema;