本文介绍了XSD序列编译到不同的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的XSD架构:
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>
当我通过JAXB处理这个模式时,我得到一个这样的字段:
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;
但我希望得到
protected List<Resistor> resisitors;
protected List<Capacitor> capacitors;
protected List<Inductor> inductors;
怎么做?
推荐答案
我找到了解决方案。需要从xs删除maxOccurs =unbounded:序列
I found solution. Need remove maxOccurs="unbounded" from xs:sequence
现在架构如下所示:
<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序列编译到不同的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!