本文介绍了JAXB List Tag创建内部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们有以下形式的XSD类型:

So we have an XSD type in the form:

<xs:complexType name="Foo">
    <xs:all>
        <xs:element name="Bars">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="Bar" type="barType" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:all>
</xs:complexType>

表示XML:

<Foo>
    <!-- Elements snipped for brevity-->
    <Bars>
        <Bar>
            <!-- Bar Element -->
        </Bar>
    </Bars>
</Foo>

xjc产生几乎正确的结果。唯一令人讨厌的事情是Bars被创建为一个内部类,它存储一个Bars列表。反正是否仍然保留了Foo中的List而仍保留上面的XML?

xjc produces almost correct results. The only annoying thing is that "Bars" is created as an inner class which stores a list of Bars. Is there anyway to have Bars be a List in Foo while still retaining the XML above?

推荐答案

另一种方法是删除周围< bars>元素,XML看起来不再那么好了,但它会使java代码更容易阅读。与xjc的简单绑定一起使用(请参阅)它将产生相当漂亮和有用的java代码。

Another way would be to drop the surrounding <bars> element, the XML does not look so nice anymore, but it would make the java code easier to read. Together with xjc's simple binding (see http://jaxb.java.net/nonav/jaxb20-fcs/docs/vendorCustomizations.html) it will produce quite pretty and usefull java code.

这篇关于JAXB List Tag创建内部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:15