From: William Victor Mote The two standard ways of dealing with XML input are SAX and DOM. SAX basically creates events as it parses an XML document in a serial fashion; a program using SAX (and not storing anything internally) will only see a small window of the document at any point in time, and can never look forward in the document. DOM creates and stores a tree representation of the document, allowing a view of the entire document as an integrated whole. One issue that may seem counter-intuitive to some new FOP developers, and which has from time to time been contentious, is that FOP uses SAX for input. (DOM can be used as input as well, but it is converted into SAX events before entering FOP, effectively negating its advantages). Since FOP essentially needs a tree representation of the FO input, at first glance it seems to make sense to use DOM. Instead, FOP takes SAX events and builds its own tree-like structure. Why? The xml document is always handled internally as SAX. The SAX events
- are used to read the elements, attributes and text data of the FO document.
- After the manipulation of the data the renderer writes out the pages in the
- appropriate format. It may write as it goes, a page at a time or the whole
- document at once. Once finished the document should contain all the data in the
- chosen format ready for whatever use. FOP can take the input XML in a number of ways: Parsing is the process of reading the XSL-FO input and making the information in it available to FOP. The two standard ways of dealing with XML input are SAX and DOM.
+SAX basically creates events as it parses an XML document in a serial fashion; a program using SAX (and not storing anything internally) will only see a small window of the document at any point in time, and can never look forward in the document.
+DOM creates and stores a tree representation of the document, allowing a view of the entire document as an integrated whole.
+One issue that may seem counter-intuitive to some new FOP developers, and which has from time to time been contentious, is that FOP uses SAX for input.
+(DOM can be used as input as well, but it is converted into SAX events before entering FOP, effectively negating its advantages). Since FOP essentially needs a tree representation of the FO input, at first glance it seems to make sense to use DOM.
+Instead, FOP takes SAX events and builds its own tree-like structure. Why? The SAX Events which are fired on the SAX Handler, class See the Input Section of the User Embedding Document for a discussion of input usage patterns and some implementation details. If the input XML is not well-formed, that will be reported. There is no DTD for XSL-FO, so no formal validation is possible at the parser level. The SAX handler will report an error for unrecognized namespaces. The element mapping is a hashmap of all the elements in a particular namespace.
This makes it easy to create a different object for each element.
Element mappings are static to save on memory. If you want FOP to be totally silent you can also set an org.apache.avalon.framework.logger.NullLogger instance. If you want to use yet another logging facility you simply have to create a class that implements org.apache.avalon.framework.logging.Logger
and set it on the Driver object. See the existing implementations in Avalon Framework for examples.
-You can supply your input to FOP from a variety of data sources.
+ The input XSL-FO document is always handled internally as SAX (see the Parsing Design Document for the rationale).
+However, the input itself can be provided in a variety of ways to FOP, which normalizes the input (if necessary) into SAX events: There are a variety of upstream data manipulations possible.
For example, you may have a DOM and an XSL stylesheet; or you may want to
set variables in the stylesheet.
-
-
-
-
- FOTreeBuilder
is the SAX Handler which is obtained through getContentHandler
on Driver
.render(Document)
method on Driver
.Driver
can take an InputSource
as input.
-This can use a Stream
, String
etc.XSLTInputHandler
is used as an InputSource
in the render(XMLReader
, InputSource
) method on Driver
FOTreeBuilder
, must represent an XSL:FO document.
-If not there will be an error.
-Any problems with the XML being well-formed are also handled here.
+
+ FOTreeBuilder
is the SAX Handler which is obtained through getContentHandler
on Driver
.render(Document)
method on Driver
.Driver
can take an InputSource
as input.
+This can use a Stream
, String
etc.XSLTInputHandler
is used as an InputSource
in the render(XMLReader
, InputSource
) method on Driver
.
-You can use the content handler from the driver to create a SAXResult. -The transformer then can fire SAX events on the content handler which -will in turn create the rendered output. -
--Examples showing this can be found at the bott +See the Examples for some variations on input.
+