XSLT in Practice - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

XSLT in Practice

Description:

Exercises 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 ... – PowerPoint PPT presentation

Number of Views:74
Avg rating:3.0/5.0
Slides: 10
Provided by: ronc4
Category:
Tags: xslt | apache | practice

less

Transcript and Presenter's Notes

Title: XSLT in Practice


1
XSLT in Practice
2
Exercises
  • 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

3
XML Serialization
4
Using 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
5
Using 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()

6
Using 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
7
Generated 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

8
Using 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
9
Javadoc
  • http//simple.sourceforge.net/download/stream/doc/
    javadoc/org/simpleframework/xml/package-summary.ht
    ml
Write a Comment
User Comments (0)
About PowerShow.com