movieXsd.xhtml 7.51 KB
Newer Older
Dr. Martin Goik's avatar
Dr. Martin Goik committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE body>
<body xml:lang="en"
xmlns="http://www.w3.org/1999/xhtml"><h1>Description</h1><p>Modeling an XML
movie database XSD schema.</p><h1 id="preparations">Preparations</h1><p>If not
yet present from another exercise download <a
href="/files/goik/Sda1/hzUUgR4399ghFFHGfbft/exam.zip"
target="_blank">exam.zip</a>, unzip it and import the resulting
<code>Exam</code> directory as a <b>Maven Eclipse</b> project into your
workspace.</p><p>Subsequently mentioned relative file and directory path names
refer to your project root.</p><h1>Tasks</h1><p>Start from
<code>Schema/movie.xsd</code>. Extend this file to provide an XML schema
grammar implementing the constraints being described in the <a
href="#dataModel">Data model description</a> section
below.</p><h1>Hints</h1><ul>
    <li>The sample data file <code>Schema/sampledata.xml</code> illustrates
    the constraints being described in the <a href="#dataModel">Data model
    description</a> section below.</li>

    <li><p>The sub directory <code>SchemaTest</code> contains unit tests
    checking your schema for correctness. Some files contained within must be
    valid and some must be invalid with respect to your
    <code>Schema/dictionary.xsd</code> implementation.</p><p>You may execute
    <code>de.hdm_stuttgart.mi.sda1.exam.xsd.SchemaTest</code> from your
    project's <code>src/test/java</code> branch as a Junit test. For a correct
    schema implementation in <code>Schema/movie.xsd</code> you'll read
    something like:</p><pre>++Instance SchemaTest/directorRef_invalid.xml: Gaining 1 point.
Dr. Martin Goik's avatar
Dr. Martin Goik committed
28
...
Dr. Martin Goik's avatar
Dr. Martin Goik committed
29
++Instance SchemaTest/personRef_invalid.xml: Gaining 1 point.
Dr. Martin Goik's avatar
Dr. Martin Goik committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
<b>14 of 14 points have been reached</b></pre><p>Possible errors:</p><dl>
        <dt>Problem: Invalid dependency file.</dt>

        <dd><pre>-- SchemaTest/210invalid_duplicateId.xml:
   Precondition file <strong>»SchemaTest/200valid_multiplePersons.xml«</strong> is invalid:
   cvc-identity-constraint.4.2.2: Duplicate key value [sKubrick] declared for identity constraint "uniquePersonId" of element "movieDb".
   Missing 1 point.</pre><p>Explanation: You will only gain points for
        <code>210invalid_duplicateId.xml</code> if the related file
        <strong>»SchemaTest/200valid_multiplePersons.xml«</strong> is valid
        with respect to your schema.</p></dd>

        <dt>Solution</dt>

        <dd>Correct your <code>Schema/movie.xsd</code> so that
        <strong>»SchemaTest/200valid_multiplePersons.xml«</strong> becomes
        valid.</dd>

        <dt style="color:red;"><strong>Problem: File should be valid /
        invalid.</strong></dt>

        <dd style="color:red;"><p>You'll find either of:</p><ul>
            <li><pre>-- <strong>SchemaTest/110invalid_duplicates.xml</strong> is expected to be invalid! Missing 1 point.</pre></li>

            <li><pre>-- <strong>SchemaTest/345valid_foo.xml</strong> is expected to be valid! Missing 1 point.</pre></li>
          </ul></dd>

        <dt style="color:green;"><strong>Solution:</strong></dt>

        <dd style="color:green;"><p>Correct your <code>Schema/movie.xsd</code>
        so that the file in question becomes valid or invalid respectively.
        The file may contain XML comments describing the expected
        error.</p></dd>
      </dl></li>
Dr. Martin Goik's avatar
Dr. Martin Goik committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  </ul><h1 id="dataModel">Data model description</h1><p>We consider
<code>Schema/sampledata.xml</code> illustrating a data store containing
dictionary data for translation services:</p><pre>&lt;movieDb  xsi:noNamespaceSchemaLocation="movie.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
    &lt;persons&gt;
        &lt;person id="rAltmann" birthYear="1925"&gt;
            &lt;name&gt;Robert Altman&lt;/name&gt;
        &lt;/person&gt;
        &lt;person id="aMacDowell" birthYear="1958"&gt;
            &lt;name&gt;Andie MacDowell&lt;/name&gt;
        &lt;/person&gt;
        &lt;person id="sKubrick" birthYear="1928" img="kubrick.jpg"&gt;
            &lt;name&gt;Stanley Kubrick&lt;/name&gt;
        &lt;/person&gt;
        &lt;person id="mModine" birthYear="1959"&gt;
            &lt;name&gt;Matthew Modine&lt;/name&gt;
            &lt;biography&gt;The youngest of seven, Matthew was born ...&lt;/biography&gt;
        &lt;/person&gt;
        &lt;person id="rLeeEremy" birthYear="1944"&gt;
            &lt;name&gt;R. Lee Ermey&lt;/name&gt;
        &lt;/person&gt;
    &lt;/persons&gt;
    &lt;movies&gt;
        &lt;movie id = "18113" year="1987" director="sKubrick" rating="8.3"&gt;
            &lt;title&gt;Full Metal Jacket&lt;/title&gt;
            &lt;cast&gt;
                &lt;actor ref="mModine" isStar="true"/&gt;
                &lt;actor ref="rLeeEremy"/&gt;
            &lt;/cast&gt;
        &lt;/movie&gt;
        &lt;movie rating="7.7" id="4342" year="1993" director="rAltmann"&gt;
            &lt;title&gt;Short Cuts&lt;/title&gt;
            &lt;cast&gt;
                &lt;actor ref="aMacDowell"/&gt;
                &lt;actor ref="mModine" isStar="false"/&gt;
            &lt;/cast&gt;
        &lt;/movie&gt;
    &lt;/movies&gt;
&lt;/movieDb&gt;</pre><p>The following integrity constraints shall be
honored:</p><ol>
    <li><p>The domain both for <code>&lt;person <b>birthYear="1928"</b>
    ...&gt;</code> and <code>&lt;movie <b>year="1987"</b> ...&gt;</code> shall
    be [1, 2100].</p><p><span
    style="color:green;font-weight: bold;">Hint:</span> Consider <a
    href="http://www.w3schools.com/xml/schema_facets.asp"
    target="_blank">http://www.w3schools.com/xml/schema_facets.asp</a>.</p></li>

    <li><p>The <code>id</code> attribute's values in e.g. <code>&lt;person
    <b>id="sKubrick"</b> ...&gt;</code> shall be of type name token and be
    unique within <code>&lt;persons&gt;</code>.</p></li>

    <li><p>The required attribute <code>&lt;movie <b>director="xyz"</b>
    ...&gt;</code> refers to a corresponding <code>&lt;person <b>id="xyz"</b>
    ...&gt;</code> element.</p></li>

    <li><p>The attributes <code>&lt;movie year="1987" rating="8.3"
    ...&gt;</code> are mandatory.</p></li>

    <li><p>The required attribute <code>&lt;actor <b>ref="xyz"</b>/&gt;</code>
    refers to a corresponding <code>&lt;person <b>id="xyz"</b> ...&gt;</code>
    element.</p></li>

    <li><p>The <code>ref</code> attribute's values in e.g. <code>&lt;actor
    <b>ref="mModine"</b>/&gt;</code> shall be unique within a given
    <code>&lt;cast&gt;</code>.</p></li>

    <li>Each actor may or may not be a star with respect to the &lt;cast&gt;
    of a given movie. This is reflected by an optional <a
    href="http://www.w3schools.com/xml/schema_dtypes_misc.asp"
    target="_blank">boolean attribute</a> <code>&lt;actor isStar="true"
    .../&gt;</code>.</li>

    <li><p>The mandatory attribute <code>rating</code> shall be of type
    decimal ranging from 0.0 to 9.9. One decimal place is allowed. Thus values
    like 3.45 are prohibited.</p><p><span
    style="color:green;font-weight: bold;">Hint:</span> Consider the
    “Restrictions on Numeric Data Types” section in <a
    href="http://www.w3schools.com/xml/schema_dtypes_numeric.asp"
    target="_blank">http://www.w3schools.com/xml/schema_dtypes_numeric.asp</a>.</p></li>
  </ol><h1 style="color: red;">Uploading, caution!</h1><ul>
    <li><p>Upon completion zip up your Maven project directory and use the
    upload facility below.</p></li>

    <li><p>Mind the remaining time! <b style="color:red;">When the examination
    terminates no subsequent uploads will be possible!</b></p></li>

    <li><p><b style="color:red;">In case of multiple uploads only your last
    uploaded zip archive will become subject to marking.</b></p></li>
  </ul></body>