Menu

Data2Xml and Xml2Data

Bruce Martin

JRecord Data2Xml and Xml2Data

These are basic Cobol-data to/from Xml programs. They where written as replacements for the Dat2Xml and Xml2Dat programs in the cb2xml project.

Limitations of Data2Xml and Xml2Data

Neither program supports:

  • Redefines

In addition to the above, Xml2Data dopes not support:

  • Duplicate field names.

If there is enough interest, I will look at enhancing the programs.

Advantages / differences from cb2xml's Dat2Xml and Xml2Dat

Advantages over cb2xml equivalents:

  • Can handle very large files.
  • Supports binary files (FB / VB formats) as well as text.
  • Better handling of Numeric fields

Differences from cb2xml's Dat2Xml and Xml2Dat:

  • <Fieldname></Fieldname> can be output as <Fieldname/>
  • Trailing spaces are dropped from Text fields. This could result in <Fieldname> </Fieldname> becoming <Fieldname/>
  • Leading spaces / zero's are dropped from numeric fields.

Program Options for Data2Xml and Xml2Data

           -cobol    - Cobol  copybook used to "interpret" the data (you must supply either a cobol or cb2xml copybook
           -cb2xml   - Cb2xml copybook used to "interpret" the data

           -input    - Input file
           -output   - Output file
           -font     - Characterset used in the Cobol data file (e.g. IBM037 for US-EBCIDIC)

           -dropCopybookName - (true/false) wether to drop the cobol copybook name from the start of the Xml Tags

           -mainXmlTag       - The outermost Xml tag to use (default coboldata)

           -fileOrganisation - "file organization" of the Cobol data file
        Text     - Standard Windows/Unix text file (single byte character-set)
        FixedWidth   - File where lines (records) are the same length no \n                                          
        Mainframe_VB - Mainframe VB, file consists of <record-length><record-data>
        GNUCobol_VB  - GNU Cobol VB, file consists of <record-length><record-data>

           -dialect  - Cobol Dialect
        Mainframe    - Mainframe cobol
        Futjitsu - Fujitsu PC cobol
        GNUCobol - GNU Cobol (little endian, ie intel)
        GNUCobolBE   - GNU Cobol (big endian, ie IBM, Sun(oracle))

Calling from Java

You can run the Cobol <==> Xml process via the following methods of Cobol2Xml class:
    Cobol2Xml.newCobol2Xml(CobolCopybook)
    Cobol2Xml.newCobol2Xml(CobolCopybookInputStream, Copybook name)
    Cobol2Xml.newCb2Xml2Xml(Cb2xmlCopybook)
    Cobol2Xml.newCb2Xml2Xml(Cb2xmlCopybookInputStream, CopybookName)

A sample call:

   1 
   2     Cobol2Xml.newCobol2Xml(opts.cobolCopybook)
   3                   .setFont(opts.font)
   4                   .setFileOrganization(opts.fileOrganisation)
   5                   .setDialect(opts.dialect)
   6                   .setDropCopybookNameFromFields(opts.dropCopybookName)
   7                   .setXmlMainElement(opts.mainXmlTag)
   8              .cobol2xml(opts.inputFile, opts.outputFile);
   9