我该如何设计我的xsd忽略元素的顺序?
<root> <a/> <b/> </root>
<root> <b/> <a/> </root>
我需要使用extension http://www.w3schools.com/schema/el_extension.asp出于代码生成的原因,所以我尝试使用以下方法all http://www.w3schools.com/schema/el_all.asp:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:t="http://www.example.com/test" >
<xs:complexType name="BaseType">
<xs:all>
<xs:element name="a" type="xs:string" />
</xs:all>
</xs:complexType>
<xs:complexType name="ExtendedType">
<xs:complexContent>
<xs:extension base="t:BaseType">
<xs:all> <!-- ERROR -->
<xs:element name="b" type="xs:string" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="root" type="t:ExtendedType"></xs:element>
</xs:schema>
但此 xsd 无效,报告以下错误<!-- ERROR -->
:
cos-all-limited.1.2:所有模型组必须出现在一个粒子中,其中 {min 发生} = {max 发生} = 1,并且该粒子必须是构成复杂类型的 {content type} 的一对的一部分定义。
的文档cos-all-limited.1.2 http://www.w3.org/TR/xmlschema-1/#cos-all-limited says:
1.2 粒子的 {term} 属性,其中 {max 出现}=1,它是构成复杂类型定义的 {content type} 的对的一部分。
我真的不太明白这个(既不是 xsd 也不是英语母语者:) ).
我是做错了事,还是做错了正确的事,还是没有办法实现这一目标?
主要编辑最初我错过了您需要使用的要求xsd:extension
。注意xsd:extension
就好像有一样xsd:sequence
基本类型的内容后跟扩展类型的内容。正如 XML Schema Primer 所说:
当复杂类型派生为
扩展,其有效的内容模型
是基本类型的内容模型
加上指定的内容模型
类型推导。此外,
两个内容模型被视为两个
连续组的孩子。
因此,似乎使这项工作有效的唯一方法是拥有一个空的基本类型并将整个替代方案存储在扩展类型中,反之亦然(基本的所有内容和一个空的扩展)。像这样:
<xsd:complexType name="ExtendedType">
<xsd:complexContent>
<xsd:extension base="BaseType">
<xsd:choice>
<xsd:sequence>
<xsd:element name="a" type="xsd:string"/>
<xsd:element name="b" type="xsd:string"/>
</xsd:sequence>
<xsd:sequence>
<xsd:element name="b" type="xsd:string"/>
<xsd:element name="a" type="xsd:string"/>
</xsd:sequence>
</xsd:choice>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="BaseType"/>
<xsd:element name="root" type="ExtendedType"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)