【发布时间】:2012-03-03 16:37:57
【问题描述】:
可能重复:
How generate XMLElementWrapper annotation with xjc and customized binding
我希望能够使用 JAXB 处理这种格式的 XML ...
<configuration>
<!-- more content here -->
<things>
<thing>
<name>xx1</name>
<value>yy1</value>
</thing>
<thing>
<name>xx2</name>
<value>yy2</value>
</thing>
</things>
<!-- more content here -->
</configuration>
我想将上述 XML 编组到这些 Java 类中(为简单起见,我留下了诸如 public、protected 以及 getter/setter 之类的修饰符):
class Configuration {
List<Thing> things;
}
class Thing {
String name;
String value;
}
我当前 XSD 结构的相关部分大致如下所示:
<complexType name="Configuration">
<sequence>
<!-- ... -->
<element name="things" type="ns:Things" minOccurs="0" maxOccurs="unbounded"/>
<!-- ... -->
</sequence>
</complexType>
<complexType name="Things">
<sequence>
<element name="thing" type="ns:Thing" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
不幸的是,XJC 还为Things 生成了一个类,即使在处理的 Java 部分中确实没有必要这样做。所以我的输出是这样的:
class Configuration {
Things things;
}
class Things {
List<Thing> thing;
}
class Thing {
String name;
String value;
}
有什么方法可以告诉 XJC 避免生成这个不必要的类吗?或者有什么办法可以重新表述我的 XSD 以避免那一代?两种选择都适合我。
事实上,我想我需要生成此处记录的@XmlElementWrapper 注释:
【问题讨论】:
标签: java xsd jaxb code-generation xjc