Title: XSLT in Practice
1XSLT in Practice
2Exercises
- download Apache Xalan - install it - try the
example in Xalan-Java Overview - http//xml.apache.org/xalan-j/
- ZVON XSLT Tutorial
- http//www.zvon.org/xxl/XSLTutorial/Output/content
s.html - ZVON Interactive Lab
- http//www.zvon.org9001/saxon/cgi-bin/XLab/XML/xl
abIndex.html?stylesheetFileXSLT/xlabIndex.xslt
3XML Serialization
4Using XML to serialize Java Classes
- import java.io.File
- import org.simpleframework.xml.Serializer
- import org.simpleframework.xml.load.Persister
- public class StorableAsXML implements
Serializable - // SERIALIZATION/DESERIALIZATION
PRIMITIVES - public void persist(File f)
- Serializer serializer new Persister()
- try
- serializer.write(this, f)
- catch (Exception ex)
- ex.printStackTrace()
-
import java.io.Serializable public class X
implements Serializable FileOutputStream
fosnull ObjectOutputStream oosnull
try fosnew FileOutputStream(f)
oos new ObjectOutputStream(fos)
oos.writeObject(this) catch
(IOException ex) ex.printStackTrace()
// using Simple XML Serialization //
http//simple.sourceforge.net/download/stream/doc/
tutorial/tutorial.php
5Using XML to serialize Java Classes
- public StorableAsXML resume(File f, Classlt?
extends StorableAsXMLgt c) - StorableAsXML retval null
- try
- Serializer serializer new
Persister() - retval (StorableAsXML)serializer.rea
d(c, f) - catch (Exception ex)
- ex.printStackTrace()
-
- return retval
-
-
- FileInputStream fisnull
- ObjectInputStream oisnull
- try
- fisnew FileInputStream(f)
- ois new ObjectInputStream(fis)
- retval(StorableAsXML)ois.readObject()
- catch (Exception ex)
- ex.printStackTrace()
-
6Using XML to serialize Java Classes
- public class Lecture extends StorableAsXML
implements Serializable - private SetltStringgt lecturersnull //non
serialized field - _at_Element(name"NAME")
- public String lectureNamenull
- _at_Element(name"DATE")
- private Date datenull
- _at_Element(name"SEQUENCE_NUMBER")
- private int sequenceNumber-1 //-1 means not
initialized - _at_Element(name"COURSE_HOME")
- private String courseRefnull //Home per il
corso - _at_Element(name"LECTURE_HOME")
- private String dirNamenull
- _at_Element(name"LECTURER",requiredfalse)
- private String lecturernull
- _at_Element(name"VIDEO",requiredfalse)
- private String videoFileNamenull
- _at_Element(name"VIDEO_LENGTH",requiredfalse)
- private String videoLenghtnull //null
Video does not exist - _at_Element(name"HAS_POST_PROCESSING")
public Lecture() // needed to be a bean //for
XMLSerialization
7Generated XML
- ltLECTUREgt
- ltNAMEgtgglt/NAMEgt
- ltDATEgt2008-09-05 162034.365 CESTlt/DATEgt
- ltSEQUENCE_NUMBERgt1lt/SEQUENCE_NUMBERgt
- ltCOURSE_HOMEgt/Users/ronchet/_LODE/COURSES/Hh_20
08 - lt/COURSE_HOMEgt
- ltLECTURE_HOMEgt01_Gg_2008-09-05lt/LECTURE_HOMEgt
- ltLECTURERgtA.B.lt/LECTURERgt
- ltHAS_POST_PROCESSINGgtfalselt/HAS_POST_PROCESSING
gt - lt/LECTUREgt
8Using XML to serialize Java Classes
- _at_Root(name"COURSE")
- public class Course extends StorableAsXML
implements Serializable - _at_Element(name"NAME")
- private String courseNamenull
- _at_Element(name"YEAR")
- private String yearnull
- _at_Element(name"COURSE_HOME")
- private String fullPathnull
- _at_ElementList(name"LECTURES",entry"LECTURE")
- private SetltStringgt lecturesnew
TreeSetltStringgt() - _at_ElementList(name"TEACHERS",entry"TEACHER_NAME
") - private SetltStringgt teachersnew
TreeSetltStringgt()
ltCOURSEgt ltNAMEgthhlt/NAMEgt ltYEARgt2008lt/YEARgt
ltCOURSE_HOMEgt/Hh_2008lt/COURSE_HOMEgt
ltLECTURES class"java.util.TreeSet"gt
ltLECTUREgt01_Gg_2008-09-05lt/LECTUREgt
lt/LECTURESgt ltTEACHERS class"java.util.TreeSet"
gt ltTEACHER_NAMEgtA.B.lt/TEACHER_NAMEgt
ltTEACHER_NAMEgtC.D.lt/TEACHER_NAMEgt
lt/TEACHERSgt lt/COURSEgt
9Javadoc
- http//simple.sourceforge.net/download/stream/doc/
javadoc/org/simpleframework/xml/package-summary.ht
ml