Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSD:使用互斥标记_Xml_Xsd_Xsd Validation - Fatal编程技术网

Xml XSD:使用互斥标记

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

我正在编写一个.xsd文件,在.xml中有一个类似于以下内容的部分

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