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

56 Views Asked by At

I have a simple element defined in this way:

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

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

But I need that the color attribute adhere to the format: "int,int,int" where each int is in the range [0,255]. Can you kindly help me defining it? Thanks in advance!

1

There are 1 best solutions below

0
On BEST ANSWER

Use XSD Restrictions to define color type:  

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

`

Use color type : `

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