Basic Features

This article introduces you to the basic usage of the JsaPar library. It uses extensive examples to demonstrate these basic 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. 


Lets start with demonstrating how to handle delimited separated value files first.



Basic features to discuss:
  1. Define schema and discuss document, line, cell options in detail.
  2. Load schema using xml schema file. Read a data source (file) where the data source structure is expressed using an external schema (xml).
  3. Simple range checking while parsing and what you can do if range is not correct.
  4. The schema should be able to express multiple type of lines and which line type to use while parsing is denoted by either a control cell or by a counter (the occurs attribute).
  5. Write the internal Document/Line/Cell classes. These are used to represent the content of the file regardless of the file format. Use matching schema with cell names.
  6. Generating files based on an existing Document/Line/Cell model and a formatting schema.
  7. Load schema expressed in xml and alter it programmatically after first write. second write with altered schema within code. show differences in output files.
  8. Demonstrate schema to express most common files in CSV and flat file format. like extra line for header, control cell, empty lines
  9. Demonstrate while parsing input data source that library is able to parse simple types such as numbers and dates and is able to handle different locale specific formatting of these special types.
  10. Demonstrate default values in schema xml both wile parsing and building.
  11. Use different Locale settings for two schemas: input is US, output is SE.
  12. Use Parser.buildJava()
  13. schema options for csv and fixed width
  14. schema definitions from xml file in stead of specifying schema in java code 
  15. Document, Line and Cell options
  16. How to compose a Document write it to a file (example without parsing!) 
  17. Use different data sources (NO files!) like StringReader and Writer to translate lines.
  18. Multiple schemas (using no converter! refer to advanced features covering Converter). actually emulating converter to show that you need Parser/Outputter when you want intervention in the conversion process. Like: It should be easy to use the library to convert files between different formats and to hook in some code (in client code!) that does some transformation on the run.
  19. class org.jsapar.input.JavaBuilder ?
  20. point to exception and error handling in special article.


Client code snippet:

public class ProductGroup {
    private int id;
    private String name;
    public int getId() { ... }
    public void setId( int id ) { ... }
    public String getName() { ... }
    public void setName( String name ) { ... }

    // other methods...
}



Library code snippet:



(TODO)
Note: If you want to process both types of file structures, you have to load two file structure classes. For example: when you want to convert a fixed width data file into a delimited separated value file, you need a file structure class for fixed width and also for delimited file structure.