XSD sequence compile to different lists

主宰稳场 提交于 2020-01-15 12:32:21

问题


I have XSD schema like this:

<xs:complexType name="Element" abstract="true">
    <xs:sequence maxOccurs="unbounded">
        <xs:element name="resistor" type="vs:Resistor" maxOccurs="unbounded"/>
        <xs:element name="capacitor" type="vs:Capacitor" maxOccurs="unbounded"/>
        <xs:element name="inductor" type="vs:Inductor" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

And when I process this schema through JAXB I get a field like this:

@XmlElements({
    @XmlElement(name = "resistor", required = true, type = Resistor.class),
    @XmlElement(name = "capacitor", required = true, type = Capacitor.class),
    @XmlElement(name = "inductor", required = true, type = Inductor.class)
})
protected List<Object> resistorAndCapacitorAndInductor;

But I want get

protected List<Resistor> resisitors;
protected List<Capacitor> capacitors;
protected List<Inductor> inductors;

How to do this?


回答1:


I found solution. Need remove maxOccurs="unbounded" from xs:sequence

Now schema look like this:

<xs:complexType name="Element" abstract="true">
<xs:sequence>
    <xs:element name="resistor" type="vs:Resistor" maxOccurs="unbounded"/>
    <xs:element name="capacitor" type="vs:Capacitor" maxOccurs="unbounded"/>
    <xs:element name="inductor" type="vs:Inductor" maxOccurs="unbounded"/>
</xs:sequence>



来源:https://stackoverflow.com/questions/16385761/xsd-sequence-compile-to-different-lists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!