XML
Beginner
1 min read
XSD Simple Types and Facets
Example
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Restriction: string with length and pattern -->
<xs:simpleType name="ISBNType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{3}-\d-\d{3}-\d{5}-\d"/>
<xs:length value="17"/>
</xs:restriction>
</xs:simpleType>
<!-- Restriction: integer range -->
<xs:simpleType name="YearType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1800"/>
<xs:maxInclusive value="2100"/>
</xs:restriction>
</xs:simpleType>
<!-- Restriction: decimal precision -->
<xs:simpleType name="PriceType">
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0"/>
<xs:totalDigits value="8"/>
<xs:fractionDigits value="2"/>
</xs:restriction>
</xs:simpleType>
<!-- List type: whitespace-separated list of tokens -->
<xs:simpleType name="TagListType">
<xs:list itemType="xs:token"/>
</xs:simpleType>
<!-- Union type: integer or "unknown" -->
<xs:simpleType name="FlexibleCount">
<xs:union memberTypes="xs:nonNegativeInteger">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="unknown"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:schema>