问题描述
我正在使用JAXB和xjc将我的XML Schema编译为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
类,并在 Item 对象> Root class?
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.
感谢您的任何建议!
最好的问候,
Markus
Best regards,Markus
推荐答案
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.
→
(仅供参考:原始链接,现已死:)
(Just for reference: the original link, now dead: http://www.conspicio.dk/blog/bjarne/jaxb-xmlelementwrapper-plugin)
这篇关于如何使用xjc和自定义绑定生成XMLElementWrapper注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!