如何在 BeanIO 中引用外部 xml 文件?
How to reference external xml files in BeanIO?
我一直在阅读 BeanIO 的模板部分,但我没有发现任何特定于带有模板的外部文件的内容。基本上,我正在尝试创建一个 xml 文件来保存我的所有模板并从其他文件中引用特定模板。
我有这个文件mytemplates.xml
<beanio>
<template name="theTemplate">
//template fields
</template>
</beanio>
我还有另一个名为 myfile.xml 的文件,它将使用来自 mytemplates.xml
的模板
<beanio>
<stream name="aaa" format="fixedlength">
<include template="theTemplate"/>
</stream>
</beanio>
有办法做到这一点吗?
为了将来参考,我在 repo 中找到了答案,并且有人在 beanIO 组中也提到了它。希望能帮助到你。
<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">
<--I had to go up to package level to make it work ie: org/app/myapp/mytemplates.xml-->
<import resource="classpath:mytemplates.xml"/>
<!-- the rest of your file -->
</beanio>
我一直在阅读 BeanIO 的模板部分,但我没有发现任何特定于带有模板的外部文件的内容。基本上,我正在尝试创建一个 xml 文件来保存我的所有模板并从其他文件中引用特定模板。
我有这个文件mytemplates.xml
<beanio>
<template name="theTemplate">
//template fields
</template>
</beanio>
我还有另一个名为 myfile.xml 的文件,它将使用来自 mytemplates.xml
的模板<beanio>
<stream name="aaa" format="fixedlength">
<include template="theTemplate"/>
</stream>
</beanio>
有办法做到这一点吗?
为了将来参考,我在 repo 中找到了答案,并且有人在 beanIO 组中也提到了它。希望能帮助到你。
<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">
<--I had to go up to package level to make it work ie: org/app/myapp/mytemplates.xml-->
<import resource="classpath:mytemplates.xml"/>
<!-- the rest of your file -->
</beanio>