Menu

Copy Book to XML and Vice versa using Meta XML

illi
2020-06-05
2020-06-09
  • illi

    illi - 2020-06-05

    Hi Bruce,
    I have a requirement to convert Cobol Copybook, to XML and vice versa, really appreciate if you could help me with some sample code or any example file.
    We are not maintaining any Copybook schema. we only have meta XML that provides element name, position
    and length.

    Meta XML looks something similar to below tags
    <item>
    <item picture="X(35)" name="address" level="01" display-length="100" storage-length="100" position="1">
    </item></item>

    my requirement is something similar to below (RecordEditorXmlLoader...)
    http://jrecord.sourceforge.net/JRecord04.html#Header_13

    Thanks in advance.

     
  • illi

    illi - 2020-06-05

    I am free to change meta xml format... something similar to below (as suggested in the wiki)


    <?xml version="1.0" ?>
    <record recsep="default" style="0" recordtype="RecordLayout" recordname="DTAR020" quote="" list="Y" fontname="CP037" filestructure="Default" copybook="DTAR020" delimiter="&lt;Tab&gt;">
    <fields>
    <field position="1" length="8" type="Char" name="KEYCODE-NO"></field></fields></record>

     
  • Bruce Martin

    Bruce Martin - 2020-06-06

    I do not undestand what you want you have written

    • I have a requirement to convert Cobol Copybook to XML

    and

    • We are not Copybook schema. we only have meta XML

    Do you want to convert a Cobol Copybook to Xml or do you want to Convert a Cobol Data file to / from Xml ???


    Meta XML looks something similar to below tags
    <item>
    <item picture="X(35)" name="address" level="01" display-length="100" storage-length="100" position="1">
    </item></item>

    This looks like the output from cb2xml. Cb2xml can produce files. You can process them in JRecord using:

    ~~~java
    Icb2xmlIOBuilder iob = JRecordInterface1.CB2XML
    .newIOBuilder("G:\Users\BruceTst01\RecordEditor_HSQL\CopyBook\cb2xml\DTAR020.xml")
    .setFont("cp037");

       AbstractLine line;
       ClassDtar020 dtar020 = DTAR020;
    
       AbstractLineReader reader  = iob.newReader("G:\\Users\\BruceTst01\\RecordEditor_HSQL\\SampleFiles\\DTAR020.bin");
    
    
       while ((line = reader.read()) != null) { 
          // line.setFieldText(recordIdx, fieldIdx, value);
          //  line.getFieldValue(dtar020.keycodeNo).set
           IFieldValue fieldValue = line.getFieldValue(dtar020.keycodeNo);
           setToSpaces1(line.getFieldValue(dtar020.keycodeNo));
    
           System.out.println(
                     "\t" + fieldValue.asString()
                   + "\t" + line.getFieldValue(dtar020.deptNo).asString()
                   + "\t" + line.getFieldValue(dtar020.qtySold).asString()
                   + "\t" + line.getFieldValue(dtar020.salePrice).asString()
                   );
       }
       reader.close();
    
     
  • illi

    illi - 2020-06-09

    Hi Bruce, Thanks for the reply.
    I want to convert Cobol Data file to XML. Application reads Cobol data file (input) from Data Queue and convert it to XML (output). I tried XmlToMainframe().convert(sourceDocument, copyBookXml) and MainframeToXml().convert(sourceFileContents, copyBookXml), it's working as per my requirement.

    Thanks.

     

Log in to post a comment.