我希望能够使用 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
这里记录的注释: