to the main page about the tutorial  THE XML REVOLUTION  -  TECHNOLOGIES FOR THE FUTURE WEB back up next

Example

A DSD 2.0 description of our recipe collections:

<dsd xmlns="http://www.brics.dk/DSD/2.0"
     xmlns:r="http://recipes.org"
     root="r:collection">

  <if><element name="r:collection"/>
    <declare><contents>
      <element name="r:description"/>
      <repeat><element name="r:recipe"/></repeat>
    </contents></declare>
  </if>

  <if><element name="r:description"/>
    <rule ref="r:ANYCONTENT"/>
  </if>

  <if><element name="r:recipe"/>
    <declare><contents>
      <sequence>
        <element name="r:title"/>
        <repeat><element name="r:ingredient"/></repeat>
        <element name="r:preparation"/>
        <element name="r:nutrition"/>
      </sequence>
      <optional><element name="r:comment"/></optional>
    </contents></declare>
  </if>

  <if><element name="r:ingredient"/>
    <declare>
      <required><attribute name="name"/></required>
      <attribute name="amount">
        <union>
          <string value="*"/>
          <stringtype ref="r:NUMBER"/>
        </union>
      </attribute>
      <attribute name="unit"/>
    </declare>
    <if><not><attribute name="amount"/></not>
      <require><not><attribute name="unit"/></not></require>
      <declare><contents>
        <repeat min="1"><element name="r:ingredient"/></repeat>
        <element name="r:preparation"/>
      </contents></declare>
    </if>
  </if>

  <if><element name="r:preparation"/>
    <declare><contents>
      <repeat><element name="r:step"/></repeat>
    </contents></declare>
  </if>

  <if>
    <or>
      <element name="r:step"/>
      <element name="r:comment"/>
      <element name="r:title"/>
    </or>
    <declare><contents>
      <string/>
    </contents></declare>
  </if>

  <if><element name="r:nutrition"/>
    <declare>
      <required>
        <attribute name="protein"><stringtype ref="r:NUMBER"/></attribute>
        <attribute name="carbohydrates"><stringtype ref="r:NUMBER"/></attribute>
        <attribute name="fat"><stringtype ref="r:NUMBER"/></attribute>
        <attribute name="calories"><stringtype ref="r:NUMBER"/></attribute>
      </required>
      <attribute name="alcohol"><stringtype ref="r:NUMBER"/></attribute>
    </declare>
  </if>

  <stringtype id="r:DIGITS">
    <repeat min="1">
      <char min="0" max="9"/>
    </repeat>
  </stringtype>

  <stringtype id="r:NUMBER">
    <sequence>
      <stringtype ref="r:DIGITS"/>
      <optional>
        <sequence>
          <string value="."/>
          <stringtype ref="r:DIGITS"/>
        </sequence>
      </optional>
    </sequence>
  </stringtype>

  <rule id="r:ANYCONTENT">
    <declare><contents>
      <repeat><union><element/><string/></union></repeat>
    </contents></declare>
  </rule>

</dsd>

Notice in particular:

This DSD is more precise than the DTD and the XML Schema descriptions:

One can check that this is indeed a DSD by validating it with the meta-DSD.

back COPYRIGHT © 2000-2003 ANDERS MØLLER & MICHAEL I. SCHWARTZBACH next