Reputation: 21
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 achieve the desired output?
Upvotes: 2
Views: 1038
Reputation: 2636
By using the xmlType="none"
attribute you can control if an xml element should be produced or not. The xmlName
is by default equal to the record name when you don't specify a xmlName
attribute, see here. A record will always be mapped to an xml element and with the use of segments, you might be able to get the desired output.
Try this mapping file:
<stream name="dist" format="xml" xmlType="none" >
<record name="HeaderRecord" class="com.mypackage.HeaderRecord" minOccurs="1" maxOccurs="1" xmlName="transaction">
<segment name="dummy" xmlType="none">
<field name="createDate" format="yyyyMMdd" />
<field name="dlrCode" />
</segment>
</record>
I don't think it is 100% what you are looking for though.
Upvotes: 1