XSD sequence compile to different lists

2019-07-22 14:44发布

问题:

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>



标签: xsd jaxb xjc