reference external xml files with templates on it.

110 views
Skip to first unread message

Joshua

unread,
May 20, 2016, 3:10:22 PM5/20/16
to beanio-users

I've been reading the templates section from BeanIO but I haven't found anything specific to external files with templates. Basically, I am trying to create a xml file that will hold all my templates and reference a specific template from other files.

I have this file mytemplates.xml

<beanio>

    <template name="theTemplate">
        //template fields
    </template>
</beanio>

and I have another file called myfile.xml that will use the templates from mytemplates.xml

<beanio>
    <stream name="aaa" format="fixedlength">
            <include template="theTemplate"/>
    </stream>
</beanio>

is there a way to accomplish this?

Nico Schlebusch

unread,
May 21, 2016, 11:05:48 AM5/21/16
to bea...@googlegroups.com
Hi Joshua,

You can do the following to import your templates:

<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">

  <import resource="classpath:mytemplates.xml"/>
 
  <!-- the rest of your file -->
</beanio>

After the 'mytemplates.xml' file has been imported, you can use it as if everything is in the same file. I actually use it for test cases where the BeanIO mapping file used by the test cases import the "real/main" BeanIO mapping file so that I don't have to pollute my real mapping file with streams etc that is only relevant to test cases.

Kind regards,
Nico Schlebusch

Joshua

unread,
May 25, 2016, 9:20:19 AM5/25/16
to beanio-users
Thanks!
Reply all
Reply to author
Forward
0 new messages