xml – 使用xs:extension忽略元素的顺序

我如何设计我的xsd来忽略元素的顺序?
<root> <a/> <b/> </root>
<root> <b/> <a/> </root>

我需要使用extension代码生成的原因,所以我尝试以下使用all

<?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: An all model group must appear in a particle with {min occurs} = {max occurs} = 1,and that particle must be part of a pair which constitutes the {content type} of a complex type deFinition.

cos-all-limited.1.2的文档说:

1.2 the {term} property of a particle with {max occurs}=1 which is part of a pair which constitutes the {content type} of a complex type deFinition.

我真的不明白这一点(既不是xsd也不是英语母语:) :).

我做错了事情,我做正确的事情错了,还是没办法实现呢?

主要编辑本来我错过了需要使用xsd:extension的要求.请注意,xsd:扩展名的工作原理就像xsd:sequence一样,其基本类型的内容后跟扩展类型的内容.正如XML Schema Primer所说:

When a complex type is derived by
extension,its effective content model
is the content model of the base type
plus the content model specified in
the type derivation. Furthermore,the
two content models are treated as two
children of a sequential group.

因此,似乎这样做的唯一方法是使用一个空的基类型,并将整个备份存储在扩展类型中,反之亦然(基本上都是空的).喜欢这个:

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

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念