1

我有这样的 XSD 架构:

<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>

当我通过 JAXB 处理这个模式时,我得到一个像这样的字段:

@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;

但我想得到

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

这个怎么做?

4

1 回答 1

1

我找到了解决方案。需要从 xs:sequence 中删除 maxOccurs="unbounded"

现在架构看起来像这样:

<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>

于 2013-05-06T06:30:19.423 回答