XSD:如何制作多态“ldquo; list”rdquo;?
我正在尝试构建一个元素类型,它保留一个
change
元素类型的列表,它是几个其他子类型的基本类型。我得到了这段代码:
<xs:complexType name="change_list" >
<xs:annotation>
<xs:documentation>List of changes.</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded" >
<xs:element name="change" type="aos:change" >
<xs:annotation>
<xs:documentation>Generic or specific type of change.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="activate" type="aos:activate" >
<xs:annotation>
<xs:documentation>Change that will activate an element or do nothing if already activated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="deactivate" type="aos:deactivate" >
<xs:annotation>
<xs:documentation>Change that will deactivate an element or do nothing if already deactivated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="switch" type="aos:switch" >
<xs:annotation>
<xs:documentation>Change that will activate the element if deactivated or deactivate it if activated.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="transform" type="aos:transform" >
<xs:annotation>
<xs:documentation>
Change that will modify the geometric state of the element
by applying one or several geometric transformations.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:sequence>
我正在使用CodeSynthesis生成C ++代码。
现在,这似乎有点过头了,因为我们在这里明确定义了对不同类型的访问。我认为我想要的更简单:
变更清单。
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="unbounded" >
<xs:element name="change" type="aos:change" >
<xs:annotation>
<xs:documentation>Generic or specific type of change.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:choice>
</xs:sequence>
现在不允许我为不同的变化子类型使用不同的标签。
所以我想也许一个好的解决方案可能是使用替换组。
但是我会放弃使用特定子类型的属性和元素的能力。
原始解决方案是否很好(具有可以获取子类型的基类型对象列表)?
没有找到相关结果
已邀请:
3 个回复
嘘伪
然后添加一个包含BaseTask子类型元素的列表:
然后xml看起来像这样:
翱抹村
贸会
这将为您提供一个XML文档,如: