Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.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模式)_Xml_Xsd_Restriction - Fatal编程技术网

对一组值的限制:定义可由许多元素使用的类型(XML模式)

对一组值的限制:定义可由许多元素使用的类型(XML模式),xml,xsd,restriction,Xml,Xsd,Restriction,我找到了以下关于一组值的限制的示例,但我不知道如何在其他元素中使用类型carType <xs:element name="car" type="carType"/> <xs:simpleType name="carType"> <xs:restriction base="xs:string"> <xs:enumeration value="Audi&q

我找到了以下关于一组值的限制的示例,但我不知道如何在其他元素中使用类型carType

<xs:element name="car" type="carType"/>

<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

也许是这样?我必须重写所有关于carType的行吗

<xs:element name="car2" type="carType"/>

<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

您只需定义一次类型:

<xs:simpleType name="carType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="Audi"/>
    <xs:enumeration value="Golf"/>
    <xs:enumeration value="BMW"/>
  </xs:restriction>
</xs:simpleType>

并根据需要将其重新用于任意多个元素:

<xs:element name="car" type="carType"/>
<xs:element name="car2" type="carType"/>