Yoon Helen
Yoon Helen

Reputation: 13

How to restrict attributes in attributeGroup?

I have this attributeGroup:

<attributeGroup name="date">
  <attribute name="year" type="int"/>
  <attribute name="month" type="int"/>
  <attribute name="day" type="int"/>
</attributeGroup>

and I want make a restriction on each attribute:

For example,

<releaseDate year="2013" month="12" day="11"/>

Upvotes: 1

Views: 236

Answers (1)

kjhughes
kjhughes

Reputation: 111491

Use xs:minInclusive and xs:maxInclusive via xs:restriction:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:attributeGroup name="dateAttrGroup">
    <xs:attribute name="year">
      <xs:simpleType>
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="1900"/>
          <xs:maxInclusive value="2020"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="month">
      <xs:simpleType>
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="1"/>
          <xs:maxInclusive value="12"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="day">
      <xs:simpleType>
        <xs:restriction base="xs:integer">
          <xs:minInclusive value="1"/>
          <xs:maxInclusive value="31"/>
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>
  </xs:attributeGroup>

  <xs:element name="releaseDate">
    <xs:complexType>
      <xs:attributeGroup ref="dateAttrGroup"/>
    </xs:complexType>
  </xs:element>

</xs:schema>

Upvotes: 1

Related Questions