A simple XML schema (XSD) sample with Complex Types and restrictions on data types. The schema is built up from bottom to top.
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://totietoot.nl/schemas/example" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://totietoot.nl/schemas/example"> <xs:simpleType name="titleType"> <xs:restriction base="xs:string"> <xs:maxLength value="50"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="written_byType"> <xs:restriction base="xs:string"> <xs:maxLength value="30"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="categoryType"> <xs:restriction base="xs:string"> <xs:enumeration value="GNU/Linux"/> <xs:enumeration value="MS Windows Server"/> <xs:enumeration value="MSSQL Server"/> <xs:enumeration value="MySQL Server"/> <xs:enumeration value="Netwerk"/> <xs:enumeration value="PowerShell Scripting"/> <xs:enumeration value="VisualBasic Scripting"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="companyType"> <xs:restriction base="xs:string"> <xs:maxLength value="15"/> </xs:restriction> </xs:simpleType> <xs:simpleType name="idType"> <xs:restriction base="xs:integer"/> </xs:simpleType> <xs:simpleType name="yearType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="1950"/> <xs:maxExclusive value="2050"/> </xs:restriction> </xs:simpleType> <xs:complexType name="manualComplexType"> <xs:sequence> <xs:element name="title" type="titleType"/> <xs:element name="written_by" type="written_byType"/> <xs:element name="category" type="categoryType"/> <xs:element name="id" type="idType"/> <xs:element name="year" type="yearType"/> </xs:sequence> </xs:complexType> <xs:complexType name="manualType"> <xs:sequence maxOccurs="unbounded"> <xs:element name="manual" type="manualComplexType"/> </xs:sequence> </xs:complexType> <xs:element name="manuals" type="manualType"/> </xs:schema>
XML example based upon above schema.
<?xml version="1.0" encoding="UTF-8"?> <manuals xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://totietoot.nl/schemas/example" xsi:schemaLocation="http://totietoot.nl/schemas/example http://totietoot.nl/schemas/example/example.xsd"> <manual> <title>PowerShell Unzip Function</title> <written_by>Tim van Kooten Niekerk</written_by> <category>PowerShell Scripting</category> <id>78</id> <year>2013</year> </manual> </manuals>