Supplying a schema

exercise No. 19

Integrity constraints


Create a suitable XML schema enforcing the following integrity constraints:

  • All elements are required.

  • The element <price> is of decimal type having two fractional digits.

  • The elements <year> and @id are of integer type.

  • The attribute @id defines a key.


<xs:schema xmlns:xs="" elementFormDefault="qualified">
		  <xs:simpleType name="money">
		  <xs:restriction base="xs:decimal">
		  <xs:fractionDigits value="2"/>
		  <xs:element name="catalog">
                  <xs:element ref="cd" minOccurs="0" maxOccurs="unbounded"/>
		  <xs:key name="uniqueId">
		  <xs:selector xpath="cd"/>
		  <xs:field xpath="@id"/>
		  <xs:element name="cd">
                  <xs:element name="title" type="xs:string"/>
                  <xs:element name="artist" type="xs:string"/>
                  <xs:element name="country" type="xs:string"/>
                  <xs:element name="company" type="xs:string"/>
                  <xs:element name="price" type="money"/>
                  <xs:element name="year" type="xs:int"/>
		  <xs:attribute name="id" type="xs:int" use="required"/>