the xml generated using generated transformers for a copybook showing garbage value.

51 views
Skip to first unread message

LS

unread,
Apr 24, 2013, 6:27:25 PM4/24/13
to legsta...@googlegroups.com
Hi Fady,
                  I generated transformers for a copybook using the following code


Cob2TransGenerator cob2trans = new Cob2TransGenerator( new Cob2TransModel());
       
        Cob2TransResult result = cob2trans.generate(cobolFile, target,classpath);  

Using the generated classes tried to convert a fixlength to xml, below is the code.
      
Path path = Paths.get("C:\\AccountBalanceRequest.txt");
   byte[] hostData = Files.readAllBytes(path);
   StringWriter writer = new StringWriter();
   AccountBalanceRequestXmlTransformers transformers = new AccountBalanceRequestXmlTransformers();
transformers.toXml(hostData, writer);
System.out.println(writer.toString());

In the xml it is showing some garbage data shown below in red.
Could you please tell me what I'm doing wrong.


COPYBOOK

"
               01 ACCOUNT-BALANCE-REQUEST.
05 TRANSACTION PIC X(4) COMP.
05 TOKEN PIC X(24) COMP.
05 ACCT-NUM PIC S9(5) COMP-4.
"

GENERATED XSD


"
     <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="unqualified">
   <xsd:complexType name="AccountBalanceRequest">
      <xsd:sequence>
         <xsd:element name="transaction">
            <xsd:annotation>
               <xsd:appinfo>
                  <cb:cobolElement cobolName="TRANSACTION"
                                   levelNumber="5"
                                   picture="X(4)"
                                   srceLine="2"
                                   type="ALPHANUMERIC_ITEM"
                                   usage="BINARY"/>
               </xsd:appinfo>
            </xsd:annotation>
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:maxLength value="4"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="token">
            <xsd:annotation>
               <xsd:appinfo>
                  <cb:cobolElement cobolName="TOKEN"
                                   levelNumber="5"
                                   picture="X(24)"
                                   srceLine="3"
                                   type="ALPHANUMERIC_ITEM"
                                   usage="BINARY"/>
               </xsd:appinfo>
            </xsd:annotation>
            <xsd:simpleType>
               <xsd:restriction base="xsd:string">
                  <xsd:maxLength value="24"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
         <xsd:element name="acctNum">
            <xsd:annotation>
               <xsd:appinfo>
                  <cb:cobolElement cobolName="ACCT-NUM"
                                   levelNumber="5"
                                   picture="S9(5)"
                                   signed="true"
                                   srceLine="4"
                                   totalDigits="5"
                                   type="BINARY_ITEM"
                                   usage="BINARY"/>
               </xsd:appinfo>
            </xsd:annotation>
            <xsd:simpleType>
               <xsd:restriction base="xsd:int">
                  <xsd:totalDigits value="5"/>
               </xsd:restriction>
            </xsd:simpleType>
         </xsd:element>
      </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="accountBalanceRequest" type="AccountBalanceRequest">
      <xsd:annotation>
         <xsd:appinfo>
            <cb:cobolElement cobolName="ACCOUNT-BALANCE-REQUEST"
                             levelNumber="1"
                             srceLine="1"
                             type="GROUP_ITEM"/>
         </xsd:appinfo>
      </xsd:annotation>
   </xsd:element>
</xsd:schema>

"

HOST DATA (AccountBalanceRequest.txt)

gtabac38475928dcfbaee98cfc8d12345


xml generated

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:AccountBalanceRequest xmlns:ns2="$coxbHelper.getXmlNamespace($binding)"><transaction>ÅÈ/Â</transaction><token>/Ä??? ?? ?ÀÄÃÂ/ÁÁ??ÄÃÄ?À</token><acctNum>825373492</acctNum></ns2:AccountBalanceRequest>



LS

unread,
May 2, 2013, 2:20:13 PM5/2/13
to legsta...@googlegroups.com
Thanks Sridhar. Whats is the default value for toXML and  toHost ?

On Thursday, May 2, 2013 7:12:13 AM UTC-7, Sridhar wrote:
I just found this.

 When you get the bytes from txt file make sure it is UTF-8

and also while transforming use UTF-8 as parameter,

AccountBalanceRequestXmlTransf
ormers transformers = new AccountBalanceRequestXmlTransformers();
transformers.toXml(hostData, writer,"UTF-8");


On Thursday, May 2, 2013 4:17:55 PM UTC+5:30, Sridhar wrote:


Can you post the Host data


LS

unread,
May 2, 2013, 5:11:00 PM5/2/13
to legsta...@googlegroups.com
I mean the default Character Encoding.

Chethan h.s

unread,
Feb 14, 2015, 7:45:04 PM2/14/15
to legsta...@googlegroups.com

Hi Sudhir
I have same problem while transforming into java objects 

 03   RECORD-KEY.
               05   CLIENT-NO           PIC  X(3).
               05   CLIENT-SUFFIX       PIC  X.
               05   LOAN-NO.
                   07   OUR-NO          PIC  X(6).
                   07   CK-DIG          PIC  X.
               05   REC-CODE            PIC  X.
               05   REC-NUMBER          PIC  999.

I am getting loan number as junk 

Record [clientNo=384, clientSuffix=1, loanNo= ?° ?? , recCode=P, recNumber=1]
I am using the IBM037 as my encoding 

This is my java code 
[

InputStream inputstream = new FileInputStream(path);
byte[] data  = new byte[4000];
int  bytesRead = inputstream.read(data);
System.out.println("bytesRead :: "+bytesRead);
int offset = 0;
while(bytesRead != -1) {
bytesRead = inputstream.read(data);
HostTransformStatus status = new HostTransformStatus();
RecordKeyTransformers recordKeyTransformers = new RecordKeyTransformers();
RecordKey recordKey = (RecordKey)recordKeyTransformers.toJava(data,offset,"IBM037");
offset += status.getHostBytesProcessed();
//LoanNo loanNum = (LoanNo) (new LoanNoHostToJavaTransformer().transform(data, "IBM037"));
if(recordKey.getRecCode().equalsIgnoreCase("P")){
System.out.println("data:"+data);
System.out.println(recordKey.toString());
}


On Thursday, May 2, 2013 at 9:12:13 AM UTC-5, Sridhar wrote:
I just found this.

 When you get the bytes from txt file make sure it is UTF-8

and also while transforming use UTF-8 as parameter,

AccountBalanceRequestXmlTransf
ormers transformers = new AccountBalanceRequestXmlTransformers();
Reply all
Reply to author
Forward
0 new messages