A product catalog

exercise No. 9

Product catalog schema Create comment in forum


Consider the following product catalog example:

<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  <title>Outdoor products</title>
    <para>We offer a great variety of basic stuff for mountaineering
          such as ropes, harnesses and tents.</para>
    <para>Our shop is proud for its large number of available
      sleeping bags.</para>
  <product id="x-223" price="233.40">
    <title>Multi freezing bag  Nightmare camper</title>
      <para>You will feel comfortable till  minus 20 degrees - At
            least if you are a penguin or a polar bear.</para>
  <product id="r-334">
    <title>Rope 40m</title>
      <para>Excellent for indoor climbing.</para>

As you may have inferred the following rules shall apply for arbitrary catalog documents:

  • Each <catalog> shall have exactly one <title> and <introduction> element.

  • <introduction> and <description> shall have at least one <para> child.

  • Each <catalog> shall have at least one <product>.

  • Each <product> shall have exactly one <title> and at least one <para> child element.

  • The required id attribute shall not contain whitespace and be unique with respect to all <product> elements.

  • The attribute price shall represent money amounts and be optional.

Provide a suitable catalog.xsd schema.


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
   vc:minVersion="1.0" vc:maxVersion="1.1">

   <xs:simpleType name="money">
      <xs:restriction base="xs:decimal">
         <xs:fractionDigits value="2"/>

   <xs:element name="title" type="xs:string"/>
   <xs:element name="para" type="xs:string"/>

   <xs:element name="description" type="paraSequence"/>
   <xs:element name="introduction" type="paraSequence"/>

   <xs:complexType name="paraSequence">
         <xs:element ref="para" minOccurs="1" maxOccurs="unbounded"/>

   <xs:element name="product">
            <xs:element ref="title"/>
            <xs:element ref="description"/>
         <xs:attribute name="id" type="xs:NMTOKEN" use="required"/>
         <xs:attribute name="price" type="money" use="optional"/>

   <xs:element name="catalog">
            <xs:element ref="title"/>
            <xs:element ref="introduction"/>
            <xs:element ref="product" minOccurs="1" maxOccurs="unbounded"/>

      <xs:key name="uniqueProductId">
         <xs:selector xpath="product"></xs:selector>
         <xs:field xpath="@id"/>