我有这样的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;
怎么做?
答案 0 :(得分: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>