XML Programming: TrAX - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

XML Programming: TrAX

Description:

... SAX Input and Output Document Object Model DOMSource Specifies ... and Output Document Object Model DOMSource Specifies document or node to process ... – PowerPoint PPT presentation

Number of Views:95
Avg rating:3.0/5.0
Slides: 15
Provided by: AndyC173
Category:

less

Transcript and Presenter's Notes

Title: XML Programming: TrAX


1
XML Programming TrAX
  • Andy Clark

2
Java API for XML Processing
  • Standard Java API for loading, creating,
    accessing, and transforming XML documents
  • JAXP parsing
  • Supports DOM and SAX
  • TrAX transformation
  • Generic transformation framework
  • Java standard extension (i.e. javax package)
  • Defined by Sun JCP

3
Transformation API for XML
  • Transformation framework
  • Allows generic transformation from one form to
    another
  • Examples
  • Serializers
  • XSLT processors
  • etc

4
javax.xml.transform (1 of 2)
  • Transformation
  • Transformer, TransformerFactory
  • Templates
  • Input and Output
  • Source
  • Result

5
javax.xml.transform (2 of 2)
  • Transformer control
  • ErrorListener
  • SourceLocator, URIResolver
  • OutputKeys
  • Other
  • TransformerConfigurationException
  • TransformerException
  • TransformerFactoryConfigurationError

6
Input and Output
  • javax.xml.transform.stream
  • StreamSource
  • StreamResult
  • javax.xml.transform.dom
  • DOMSource, DOMResult
  • DOMLocator
  • javax.xml.transform.sax
  • SAXSource, SAXResult
  • SAXTransformerFactory
  • TransformerHandler, TemplatesHandler

7
Stream Input and Output
  • StreamSource
  • Specifies document stream to parse
  • StreamResult
  • Specifies stream for serialization of document
  • OutputKeys controls serialization settings

8
DOM/SAX Input and Output
  • Document Object Model
  • DOMSource
  • Specifies document or node to process
  • DOMResult
  • Specifies document factory for new nodes
  • Simple API for XML
  • SAXSource
  • Specifies XMLReader to parse document
  • SAXResult
  • Specifies handler for generated events

9
Transform Document (1 of 3)
  • Identity transform
  • Get instance of transformer factory
  • TransformerFactory factory TransformerFactory.ne
    wInstance()
  • Create transformer
  • Transformer transformer factory.newTransformer()
  • Create input and output
  • Source source new StreamSource(document.xml)
  • Result result new StreamResult(System.out)
  • Transform document
  • transformer.transform(source, result)

10
Transform Document (2 of 3)
  • Transform with stylesheet (1 of 2)
  • Get instance of transformer factory
  • TransformerFactory factory TransformerFactory.ne
    wInstance()
  • Create templates
  • Source templatesSource new StreamSource(style.x
    sl)
  • Templates templates factory.newTemplates(templat
    esSource)
  • Create transformer
  • Transformer transformer templates.newTransformer
    ()

11
Transform Document (3 of 3)
  • Transform with Stylesheet (2 of 2)
  • Create input and output
  • Source source new StreamSource(document.xml)
  • Result result new StreamResult(System.out)
  • Transform document
  • transformer.transform(source, result)

12
Error Handling and Entity Resolution
  • Transformer
  • Can set a TrAX ErrorListener
  • Can set a TrAX URIResolver
  • URIResolver
  • Called when reference to multiple documents
  • Passed base and literal system identifiers of
    resource
  • Example XPath document(book.xml)/book/title
  • Returns a TrAX Source
  • Note This is super cool because it means that
    you can cache (or generate) documents in memory.

13
Useful Links
  • JAXP
  • http//java.sun.com/xml/
  • Apache Xalan XSLT Processor
  • http//xml.apache.org/xalan-j/

14
XML Programming TrAX
  • Andy Clark
Write a Comment
User Comments (0)
About PowerShow.com