Reading/parsing a copybook in text format using JRecord, the builder seems to think it's an XML file

324 Views Asked by At

I'm trying to read,parse a copybook in .txt format using JRecord and then process a binary file using the copybook schema.

When I try to read the binary file using schemaBuilder.newReader(binaryFile), it gives me an exception saying :-

CopybookFile.txt:1:1:net.sf.JRecord.Common.RecordException : Content is not allowed in prolog.

The nested exception seems to be a SAXParseException with the same message.

I notice that while using the IOBUilder with the copybook file, the loader seems to be an XMlCopyBookLoader and not a cobol file loader. How do I make the IOBuilder recognise that I'm trying to parse a txt/cbl file?

Minimal sample below :

ICobolIOBuilder schemaBuilder = JRecordInterface1.COBOL.newIOBuilder(copyBookFilePathWithDotTxt).setDialect(1).setFont("cp037").setDropCopyBookNameFromFields(true); // using the debugger, I see that schemaBuilder.loader is an  XMLCopyBookLoader and schemaBuilder is of type CblIOBuilderMultiSchema
try { 
AbstractLineReader reader = schemaBuilder.newReader(binaryFilePath);
} catch(Exception e) { e.printStackTrace(); }

I have tried using the same file with .cbl extension as well. I also know that it's able to read the file because if I put xml content in there it seems to atleast move till the first invalid character. i.e line after XML.

java version - 8

JRecord version 0.81.5

1

There are 1 best solutions below

1
On

From the bugs section in the JRecord source forge, it was infered that cb2xml is to be added as a dependency separately sometime between 0.80.5 and 0.81.5 . On adding it I was able to parse the copybook correctly.