如何限制attributeGroup中的属性?
How to restrict attributes in attributeGroup?
我有这个attributeGroup
:
<attributeGroup name="date">
<attribute name="year" type="int"/>
<attribute name="month" type="int"/>
<attribute name="day" type="int"/>
</attributeGroup>
我想对每个属性进行限制:
- 年份必须是 1900~2020
- 月份必须是01~12
- 日期必须是 01~31
例如,
<releaseDate year="2013" month="12" day="11"/>
通过 xs:restriction
使用 xs:minInclusive
和 xs:maxInclusive
:
<?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>
我有这个attributeGroup
:
<attributeGroup name="date">
<attribute name="year" type="int"/>
<attribute name="month" type="int"/>
<attribute name="day" type="int"/>
</attributeGroup>
我想对每个属性进行限制:
- 年份必须是 1900~2020
- 月份必须是01~12
- 日期必须是 01~31
例如,
<releaseDate year="2013" month="12" day="11"/>
通过 xs:restriction
使用 xs:minInclusive
和 xs:maxInclusive
:
<?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>