質問

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?

役に立ちましたか?

解決

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>

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top