Xml XSD:使用互斥标记
我正在编写一个.xsd文件,在.xml中有一个类似于以下内容的部分Xml XSD:使用互斥标记,xml,xsd,xsd-validation,Xml,Xsd,Xsd Validation,我正在编写一个.xsd文件,在.xml中有一个类似于以下内容的部分 <time start="2006-10-02T09:15:26.43Z" /> -或- 我最初的研究让我在XSD中使用标记,就像这样 <xs:element name="time"> <xs:complexType> <xs:choice> <xs:element name="start">
<time start="2006-10-02T09:15:26.43Z" />
-或-
我最初的研究让我在XSD中使用标记,就像这样
<xs:element name="time">
<xs:complexType>
<xs:choice>
<xs:element name="start">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:pattern value=".*Z" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="end">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:pattern value=".*Z" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
当我对照一个已知的商品检查我的XSD时,我得到一个错误,即“属性‘start’不允许出现在元素‘time’中”
知道我哪里出错了吗
编辑:显然,我使用1.0很重要,因为这意味着我没有断言的权限。在您的实例文档中,
start
和end
是属性,但是您已经在模式中将它们声明为元素。需要使用xs:attribute
来声明它们
在XSD 1.0中,您可以声明两个可选属性,但不能声明它们是互斥的。为此,您需要XSD 1.1和xs:assert
<xs:element name="time">
<xs:complexType>
<xs:choice>
<xs:element name="start">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:pattern value=".*Z" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="end">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:pattern value=".*Z" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>