我正在编写一个.xsd文件,并且在.xml中有一个类似于以下内容的部分
<time start="2006-10-02T09:15:26.43Z" />
-OR-
<time end="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时,收到错误消息“元素'时间'中不允许出现'属性'开始'。
知道我哪里出错了吗?
编辑:显然,我使用1.0很重要,因为那将意味着我无权声明。
在您的实例文档中,start
和end
是属性,但是您已在模式中将它们声明为元素。它们需要使用xs:attribute
声明。