xml – 使用xs:extension忽略元素的顺序
我如何设计我的xsd来忽略元素的顺序?
<root> <a/> <b/> </root> <root> <b/> <a/> </root> 我需要使用 <?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的文档说:
我真的不明白这一点(既不是xsd也不是英语母语:) :). 我做错了事情,我做正确的事情错了,还是没办法实现呢?
主要编辑本来我错过了需要使用xsd:extension的要求.请注意,xsd:扩展名的工作原理就像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"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |