Advanced Features

This article introduces you to the advanced usage of the JsaPar library. It uses extensive examples to demonstrate these advanced features. Examples are provided both for fixed width and delimited separated value data sources. This article assumes that you already have followed the instructions in the setting up article of this website, and that you have familiarized yourself with the API of the JsaPar library explained in the getting started article of this website. If not, please make sure that you have read these articles before continuing reading this article.

The advanced features that are discussed in this article are:
- ?

Advanced features to discuss:

  1. Regexp validation while parsing
  2. It is possible to also build an output giving one line at a time, thus be able to handle large files without congesting the memory. Is this event based? If so, move to event handling article.
  3. Converting into Java Objects directly.
  4. Use the Converter tool, Using the converter to convert fixed width into delimited: class
  5. Use the ConverterMain tool from command line using manifest file options
  6. LineManipulator that you can plugin to manipulate files while converting.
  7. handling complex control cell structures (still limited to first cell, damnit!)
  8. XmlDocumentParser, load in a data source file that is specified in xml! Using xml as data file input: class org.jsapar.input.XmlDocumentParser
  9. Discuss more schema options, like ignore read/write
  10. Transformations of Document objects? Document 1 into Document 2 (using jsapar to change documents memory so you get 2 different Document structures with different Line and Cell structures. Not to be confused with different schemas for the same Document object!
  11. Splitting a data file into multiple data files of another structure. One input, two output files.
  12. Use converter with string readers as a daisy chain to handle complex issues that cannot be done in "one go". Think of complex example to illustrate.
  13. Explain usage of Xml2SchemaBuilder
  14. Example of converting a CSV file into a list of Java objects according to an xml-schema
<line occurs="*" linetype="org.jsapar.TstPerson" cellseparator=";">

Example of reading CSV file into a Document object according to an xml-schema:

Reader schemaReader = new FileReader("samples/01_CsvSchema.xml");
Xml2SchemaBuilder xmlBuilder = new Xml2SchemaBuilder();
Reader fileReader = new FileReader("samples/01_Names.csv");
Parser parser = new Parser(;
Document document =;

Example of converting a Fixed width file into a CSV file according to two xml-schemas:

File outFile = new File("samples/02_FixedWidthSchema.xml");
Reader inSchemaReader = new FileReader("samples/01_CsvSchema.xml");
Reader outSchemaReader = new FileReader(outFile);
Xml2SchemaBuilder xmlBuilder = new Xml2SchemaBuilder();
Reader inReader = new FileReader("samples/01_Names.csv");
Writer outWriter = new FileWriter("samples/02_Names_out.txt");
Converter converter = new Converter(,;
converter.convert(inReader, outWriter);

Example of converting a CSV file into a list of Java objects according to an xml-schema:

Reader schemaReader = new FileReader("samples/07_CsvSchemaToJava.xml");
Xml2SchemaBuilder xmlBuilder = new Xml2SchemaBuilder();
Reader fileReader = new FileReader("samples/07_Names.csv");
Parser parser = new Parser(;
List parseErrors = new LinkedList()
List people = parser.buildJava(fileReader, parseErrors);