如何定义格式为 "int,int,int" 的属性,其中每个 int 位于 [0,255] , XSD 1.1

How to define an attribute with a format "int,int,int" where each int is in [0,255] , XSD 1.1

我有一个这样定义的简单元素:

<xs:element name="stat" type="statType" />

<xs:complexType name="statType">
    <xs:attribute name="color" use="required"/>
</xs:complexType>

但我需要颜色属性遵循以下格式:"int,int,int" 其中每个 int 都在 [0,255] 范围内。你能帮我定义一下吗?提前致谢!

使用XSD限制来定义颜色类型:

<xs:simpleType name="colorValue">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="0"/>
    <xs:maxInclusive value="255"/>
  </xs:restriction>
</xs:simpleType>

`

使用颜色类型: `

<xs:element name="stat" type="statType" />

<xs:complexType name="statType">
    <xs:attribute name="colorR" type="colorValue" use="required"/>
    <xs:attribute name="colorG" type="colorValue" use="required"/>
    <xs:attribute name="colorB" type="colorValue" use="required"/>
</xs:complexType>