如何使用 xjc 和自定义绑定生成 XMLElementWrapper 注释 [英] How generate XMLElementWrapper annotation with xjc and customized binding
问题描述
我正在使用 JAXB 和 xjc 将我的 XML 模式编译成 Java 类.我不想手动编辑这个生成的类.我有这样的 xml 架构:
I'm using JAXB and xjc to compile my XML Schema into Java classes. I do not want to manually edit this generated classes. I have xml schema like that:
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="items">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
xjc 生成一个 Items
类,它只包含一个 Item
对象的列表.是否有机会省略 Items
类并直接在 Root
类中有一个 Item
对象列表?
The xjc generates a class Items
that only contains a list of Item
objects. Is there any chance to omit the class Items
and have a list of Item
objects directly in the Root
class?
我知道这可以通过 @XMLElementWrapper
注释来完成,但我不知道如何告诉 xjc 创建这样的.
I know that this can be done with @XMLElementWrapper
annotation, but I don't know how to tell xjc to create such.
感谢您的任何建议!
最好的问候,马库斯
推荐答案
Bjarne Hansen 为 xjc 开发了一个插件,可以解决这个问题.不幸的是,原始实现的链接现已失效.但是,Dmitry Katsubo 在 github 上有一个项目,基于 Bjarne 的原始代码并进行了一些额外的改进.
Bjarne Hansen developed a plugin for xjc that was able to take care of this. Unfortunately, the link to the original implementation is now dead. However, there is a project by Dmitry Katsubo on github, based on Bjarne's original code with some additional improvements.
→ https://github.com/dmak/jaxb-xew-plugin
(仅供参考:原链接,现已失效:http:///www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin)
(Just for reference: the original link, now dead: http://www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin)
这篇关于如何使用 xjc 和自定义绑定生成 XMLElementWrapper 注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!