Sample java for EXI encoding / decoding?

I am looking for an example Java program to encode / decode EXI (Efficient XML Exchange) streams using EXIficient or OpenEXI .

Can anyone help? I can not find an example application.

edit: Alternatively, if someone could point me to documentation that would allow me to use EXIficient or OpenEXI, that would be helpful. I found javadoc, but I have no idea which classes to use.

Or, as @StaxMan points out, is there a specific mention / discussion of the appropriate top-level classes for use with one of the standard XML APIs?

+5
source share
5 answers

Using Exificient , I was able to encode and decode the XML sample as EXI, using a fragment from their "Help" and their "demos" , I was able to get after working using only the Maven dependency

<dependency>
    <groupId>com.siemens.ct.exi</groupId>
    <artifactId>exificient</artifactId>
    <version>0.9.4</version>
</dependency>

with code

import com.siemens.ct.exi.EXIFactory;
import com.siemens.ct.exi.GrammarFactory;
import com.siemens.ct.exi.api.sax.EXIResult;
import com.siemens.ct.exi.api.sax.EXISource;
import com.siemens.ct.exi.helpers.DefaultEXIFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;


// based on: https://sourceforge.net/p/exificient/code/HEAD/tree/tags/exificient-0.9.4/src/sample/java/EXIficientDemo.java?format=raw
public class MinimalistExificientSample {

    static final boolean USE_SCHEMA = true;

    public static void main(String[] args) throws Exception{
        File xmlIn  = new File( "/home/artb/spring-core-4.1.6.RELEASE.pom.xml" );
        FileInputStream xmlIns = new FileInputStream( xmlIn );

        File exi = new File( "/home/artb/spring-core-4.1.6.RELEASE.pom." +(USE_SCHEMA? "schema":"schemaless")+  ".exi" )
        FileOutputStream exiOuts = new FileOutputStream( exi );

        File xmlOut  = new File( "/home/artb/spring-core-4.1.6.RELEASE.pom." +(USE_SCHEMA? "schema":"schemaless")+ ".xml" );

        //settings
        EXIFactory exiFactory = DefaultEXIFactory.newInstance();
        exiFactory.setGrammars( GrammarFactory.newInstance().createGrammars( "/home/artb/maven-4.0.0.xsd" ) );

        // encode
        InputSource xmlIs = new InputSource( xmlIns );
        EXIResult exiResult = USE_SCHEMA ? new EXIResult(exiFactory) : new EXIResult();
        exiResult.setOutputStream( exiOuts );
        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
        xmlReader.setContentHandler( exiResult.getHandler() );
        xmlReader.parse( xmlIs );

        // decode
        FileOutputStream xmlOuts = new FileOutputStream( xmlOut );
        FileInputStream exiIns = new FileInputStream( exi );
        InputSource exiIs = new InputSource( exiIns );
        EXISource exiSource = USE_SCHEMA ? new EXISource(exiFactory) : new EXISource();
        exiSource.setInputSource(exiIs);
        exiSource.setXMLReader( exiSource.getXMLReader() );
        TransformerFactory.newInstance().newTransformer().transform(exiSource, new StreamResult(xmlOuts));
    }

}

use Maven XSD and Spring 4.1.6 POM from the center of Maven as sample data.

Nb: that the XML output should be equivalent to input, but not necessarily equal, because comments and spaces are lost, and namespace aliases (? Can the wrong term be used here) are arbitrarily assigned.

+4
source

; , XML- API XML-, SAX, Stax DOM (, ). , EXI - XML Infoset; , XML.

, , API- API?

+2

EXIfiecient, .

0

OpenEXI , 2 3 .

  • EXISchemaFactory org.openexi.fujitsu.scomp XML- EXISchema.
  • EXISchema .
  • EXISchema .
  • GrammarCache org.openexi.fujitsu.proc.grammars , EXISchema .
  • Transmogrifier org.openexi.fujitsu.sax, GrammarCache setEXISchema (grammarCache).
  • XML- EXI encode (InputSource is) .
  • EXIDecoder org.openexi.fujitsu.proc EXI . EXIDecoder GrammarCache InputStream . processHeader() EXI. nextEvent() , , null.

, null GrammarCache .

, , .

0
source

OpenEXI now provides a tutorial [1] on how to work with it.

[1] http://openexi.sourceforge.net/tutorial/

In addition, this forum in the OpenEXI discussion forum [2] shows code for converting from binary XML to Java (JaXB) Java using the EXXeader SAX XMLReader implementation:

[2] http://sourceforge.net/p/openexi/discussion/800031/thread/3103260f/?limit=50#2191

0
source

All Articles