<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也不是英语母语:) :).
我做错了事情,我做正确的事情错了,还是没办法实现呢?
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"/>