用JAXB合并多个文件 [英] merge multiple files with JAXB

查看:63
本文介绍了用JAXB合并多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用stackoverflow,而且我的英语说得不太好,请保持友善.

It's the first time I'm using stackoverflow and I don't speak English perfectly so be nice please.

我在类似附加模式下使用Jaxb

I'm using Jaxb in append mode like that

for (Document330 document : documents){
  JAXBContext jContext = JAXBContext.newInstance(Document330Xml.class);
    Marshaller m = jContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    m.marshal(document, fos);
}

我有一个类似的输出文件:

And I have an output file like that:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
    <MAILING>
        <REF>M584</REF>
        <LIBELLE>Mail Test 1</LIBELLE>
    </MAILING>
</DOCUMENT>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT>
    <MAILING>
        <REF>M585</REF>
        <LIBELLE>Mail Test 2</LIBELLE>
    </MAILING>
</DOCUMENT>

但是我想要这样的东西:

but I want something like that :

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENTS>
    <DOCUMENT>
        <MAILING>
            <REF>M584</REF>
            <LIBELLE>Mail Test 1</LIBELLE>
        </MAILING>
    </DOCUMENT>
    <DOCUMENT>
        <MAILING>
            <REF>M585</REF>
            <LIBELLE>Mail Test 2</LIBELLE>
        </MAILING>
    </DOCUMENT>
</DOCUMENTS>

但是我可能有很多XML.所以我认为解组不是最好的解决方案

But it is possible that I have many XML. So I do not think the Unmarshaller is the best solution

感谢您的阅读

推荐答案

如果我没记错的话,您需要创建一个Documents330Xml类,可以将其编组(您可以查看Document330Xml类以供参考) ).此类需要Document330Xml的列表作为字段.

If I remind correctly, you need to create a Documents330Xml class, which can be marshalled (you can have a look at your Document330Xml class for reference). This class needs a list of Document330Xml as field.

如果随后编组Documents330Xml类,则应该获得所需的XML.

If you then marshall the Documents330Xml class, you should get the desired XML.

这篇关于用JAXB合并多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆