Header fileds in Xml file

26 views
Skip to first unread message

Behnam Hashemi

unread,
Jan 8, 2019, 12:12:51 PM1/8/19
to beanio-users

Hi everyone,
I'm trying to generate the following xml file which has 2 fields as Header and the Repeating section "rec" node :


<?xml version="1.0" encoding="UTF-8"?>

<transaction>

<createDate>20160708</createDate>
<dlrCode>100<dlrCode/>


<rec>

   
<processDate>20190108</processDate>

   
<srcID/>10<srcID/>

</rec>

<rec>

   
<processDate>20190108</processDate>

   
<srcID/>11<srcID/>

</rec>
<rec>

   
<processDate>20190108</processDate>

   
<srcID/>12<srcID/>

</rec>
</transaction>


This is the mapping file which I created: 

<?xml version="1.0" encoding="UTF-8"?>
<beanio xmlns="http://www.beanio.org/2012/03"
 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">

 
<stream name="dist" format="xml" xmlName="transaction" >
     
<record name="HeaderRecord" class="com.myPackage.HeaderRecord" minOccurs="1" maxOccurs="1" order="1" >
       
<field name="createDate" format="yyyyMMdd" />
       
<field name="dlrCode" />
   
</record>
   
<record name="DisRecord" class="com.myPackage.Record" minOccurs="0" maxOccurs="unbounded" xmlName="rec" order="2">
       
<field name="processDate" format="yyyyMMdd"/>
       
<field name="srcID"/>
   
</record>
 
</stream>
</beanio>







But the problem is, it generates the header fields inside the HeaderRecord node like this:


<?xml version="1.0" encoding="UTF-8"?>

<transaction>


<HeaderRecord>
     <createDate>20160708</createDate>
     
<dlrCode>100<dlrCode/>
</HeaderRecord>


<rec>

   
<processDate>20190108</processDate>

   
<srcID/>10<srcID/>

</rec>

<rec>

   
<processDate>20190108</processDate>

   
<srcID/>11<srcID/>

</rec>
<rec>

   
<processDate>20190108</processDate>

   
<srcID/>12<srcID/>

</rec>
</transaction>




Is there something misconfigured in the mapping file? How to resolve it?

I'm really blocked on it, Thanks every one in advance 

Nico Schlebusch

unread,
Jan 8, 2019, 4:07:07 PM1/8/19
to bea...@googlegroups.com
Hi,

What does your objects/POJO's look like?

Kind regards,
Nico

Behnam Hashemi

unread,
Jan 8, 2019, 4:48:19 PM1/8/19
to beanio-users
Here are the POJO's (Header and Detail):

public class HeaderRecord implements Serializable {
private static final long serialVersionUID = 1L;

private Date createDate;
private String dlrCode;

    //setter and getter
}


public class Record implements Serializable {
private static final long serialVersionUID = 1L;

private Date processDate;
private String srcID;

    //setter and getter
}

Nico Schlebusch

unread,
Jan 9, 2019, 3:29:02 AM1/9/19
to bea...@googlegroups.com
Hi,

Don't you have another a POJO that is composed of the 'HeaderRecord' and a List<Record> of 'Records'? I think that is what you need to accomplish the desired output. Then also see
1 - http://beanio.org/2.1/docs/reference/index.html#XmlSegments
2 - http://beanio.org/2.1/docs/reference/index.html#XmlStreams
3 - http://beanio.org/2.1/docs/reference/index.html#XmlGroups

If not, how do you write your data to the xml format with BeanWriter? Multiple calls to BeanWriter.write(..) ?

Kind regards,
Nico Schlebusch

Nico Schlebusch

unread,
Jan 9, 2019, 3:33:02 AM1/9/19
to bea...@googlegroups.com

Don't you have another a POJO that is composed of the 'HeaderRecord' and a List<Record> of 'Records'?
OR
Your 'HeaderRecord' could contain the List<Record> objects instead of another POJO.

Kind regards,
Nico Schlebusch

Behnam Hashemi

unread,
Jan 9, 2019, 10:29:08 AM1/9/19
to beanio-users
Since the xml data is  huge, I do multiple calls to BeanWriter.write(..) per each repeating POJO (detail) and one call for header POJO, ,By putting  the List<Record> objects inside the header POJO and do a single call to BeanWriter.write(..) ,
it will possible to run out of memory (heap space) .

Nico Schlebusch

unread,
Jan 9, 2019, 11:23:40 AM1/9/19
to bea...@googlegroups.com
Ok, I'm not sure how you will achieve the desired output. I would like to know how you get the closing </transaction> tag to be at the end of the xml, then it might work.

Try this to "remove" the <HeaderRecord> element from the output.
  <stream name="dist" format="xml" xmlType="none">
    <record name="HeaderRecord" class="com.mypackage.HeaderRecord" minOccurs="1" maxOccurs="1" xmlName="transaction">

      <field name="createDate" format="yyyyMMdd" />
      <field name="dlrCode" />
    </record>


Kind regards,
Nico Schlebusch


Behnam Hashemi

unread,
Jan 9, 2019, 6:07:56 PM1/9/19
to beanio-users
Thanks Niko, But it still generates the wrong structure, the  </transaction> must be end of the file, see the generated file:

<?
xml version="1.0" encoding="UTF-8"?>

<transaction>
  <createDate>20160708</createDate>
    <dlrCode>100<dlrCode/>

</transaction>

<rec>

    
<processDate>20190108</processDate>

    
<srcID/>10<srcID/>

</rec>

<rec>

    
<processDate>20190108</processDate>

    
<srcID/>11<srcID/>

</rec>
<rec>

    
<processDate>20190108</processDate>

    
<srcID/>12<srcID/>

</rec>


Reply all
Reply to author
Forward
0 new messages