EXIficient - open source implementation of the W3C Efficient XML Interchange (EXI) format specification.
The EXI format is a very compact representation for the Extensible Markup Language (XML) Information Set that is intended to simultaneously optimize performance and the utilization of computational resources.
- SAX 1
- SAX 2
- DOM
- StAX
<dependency>
<groupId>com.siemens.ct.exi</groupId>
<artifactId>exificient</artifactId>
<version>0.9.6</version>
</dependency>
- Java 1.5 or higher
- Xerces2 Java Parser 2.9.11 or higher for schema-informed mode
/*
* Setup EXIFactory as required
*/
EXIFactory exiFactory = DefaultEXIFactory.newInstance();
// e.g., add additional settings beyond the default values
// exiFactory.setGrammars(GrammarFactory.newInstance().createGrammars("foo.xsd")); // use XML schema
// exiFactory.setCodingMode(CodingMode.COMPRESSION); // use deflate compression for larger XML files
/*
* encode XML to EXI
*/
String fileEXI = "foo.xml.exi"; // EXI output
OutputStream osEXI = new FileOutputStream(fileEXI);
EXIResult exiResult = new EXIResult(exiFactory);
exiResult.setOutputStream(osEXI);
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler( exiResult.getHandler() );
xmlReader.parse("foo.xml"); // parse XML input
osEXI.close();
/*
* decode EXI to XML
*/
String fileXML = "foo.xml.exi.xml"; // XML output again
Result result = new StreamResult(fileXML);
InputSource is = new InputSource(fileEXI);
SAXSource exiSource = new EXISource(exiFactory);
exiSource.setInputSource(is);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(exiSource, result);
EXIficient also provides a command-line interface.
/* Class: com.siemens.ct.exi.cmd.EXIficientCMD */
#########################################################################
### EXIficient ###
### Command-Shell Options ###
#########################################################################
-h /* shows help */
-encode
-decode
-i
-o
-schema
-xsdSchema /* XML schema datatypes only */
-noSchema /* default */
-strict
-preservePrefixes
-preserveComments
-preserveLexicalValues
-preservePIs /* processing instructions */
-preserveDTDs /* DTDs & entity references */
-bytePacked
-preCompression
-compression
-blockSize
-valueMaxLength
-valuePartitionCapacity
-noLocalValuePartitions /* EXI Profile parameters */
-maximumNumberOfBuiltInProductions
-maximumNumberOfBuiltInElementGrammars
-includeOptions
-includeCookie
-includeSchemaId
-includeSchemaLocation
-includeInsignificantXsiNil
-includeProfileValues
-retainEntityReference
-fragment
-selfContained <{urn:foo}elWithNS,elDefNS>
-datatypeRepresentationMap
# Examples
-encode -schema notebook.xsd -i notebook.xml
-decode -schema notebook.xsd -i notebook.xml.exi -o notebookDec.xml