samples.transform
Class XMLToFastInfosetStAXSerializer

java.lang.Object
  extended by samples.transform.XMLToFastInfosetStAXSerializer

public class XMLToFastInfosetStAXSerializer
extends Object

Serializes an XML input stream into FI document using StAX document serializer defined in the fastinfoset.stax package.

The sample demonstrates how to use StAXDocumentSerializer as a SAX handler and JAXP transformer to convert an XML file into a FI document. As shown in the sample, transforming a DOM source to SAX Result involves very little coding. However, the process may not be efficient due to the construction of DOM source. In the sample, a DOMSource is constructed out of an XML file input (see method getDOMSource) and a SAXResult is instantiated using an instance of SAX2StAXWriter as handlers (see method getSAXResult). Utility class SAX2StAXWriter extends DefaultHandler and implements LexicalHandler, which allows it to be used to handle SAX events. The source and result are then used by the JAXP transformer to transform the XML file to FI document which was passed in as OutputStream for the StAX serializer object. The XML inputstream is first transformed into a ByteArrayOutputStream that may be used for other processing. In this sample, we simply write it out into a file.


Constructor Summary
XMLToFastInfosetStAXSerializer()
          Creates a new instance of DocumentSerializer
 
Method Summary
static void main(String[] args)
          Starts the sample.
 void write(File input, File output)
          Transform an XML file into a FI document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLToFastInfosetStAXSerializer

public XMLToFastInfosetStAXSerializer()
Creates a new instance of DocumentSerializer

Method Detail

write

public void write(File input,
                  File output)
Transform an XML file into a FI document.

Parameters:
input - an XML file input
output - the FI document output

main

public static void main(String[] args)
Starts the sample.

Parameters:
args - XML input file name and FI output file name


Copyright © 2012 Oracle Corpration. All Rights Reserved.