here - School of Engineering and Computer Science

Assignment 3
SWEN432-15/ass3(pm)
School of Engineering and Computer Science
SWEN 432
Advanced Database Design and Implementation
Assignment 3
Due date: Monday 11 May at 23:59
The objective of this assignment is to test your understanding of:
 Document Type Definition, (DTD),
 XML Documents,
 XML Schema, and
 Identity constraints of XML Schema.
The Assignment is worth 4.0% of your final grade. The Assignment is marked out
of 100.
Submit your answers to assignment questions via the school electronic
submission system and a printed version in the hand-in box in the second floor of
the Cotton Building.
When doing the assignment you will need to use the xmllint XML parser to
check whether your XML documents are valid with regard to a DTD or an XML
Schema schema.
You can use xmllint from UNIX shell. To do so, type
>xmllint
To get information how to use xmllint, type
>man xmllint
Include your commands and xmllint messages from the shell prompt in your
answers.
The xmllint parser does not recognize the syntax of new elements (like
xsd:assert) introduced in XSD 1.1. Pavle downloaded Xerces2 Java free XSD
1.1 parser and validator from:
https://jeszysblog.wordpress.com/2012/09/27/free-and-opensource-xsd-1-1-validation-tool/
SWEN432/Assignment 3
1
continued
and it does the job.
You may find the validator here:
/vol/courses/swen432/xsd11-validator.jar
You may run the validator using the command
%java –jar
<xml_file>
xsd11validator.jar
–sf
<xsd_schema_file>
-if
You may also realize that xmllint does not perform IDREF checking when it
validates a document against an XML Schema. If you need to validate
ID/IDREF constraints using XML Schema, use Xerces2 Java instead.
Question 1. Producing a valid dancingCompetition.xml
File and Mapping a DTD to XML Schema
[30 marks]
There is a dancingCompetiton_15.dtd schema given on the Assignments
course page. The schema describes dancing competitions. Dancing competitions
are held in different New Zealand cities. Different competitions may be held in the
same city on different dates, two different competitions can take place in two
different cities on the same date. In each competition pairs of dancers dance
different dances and score points for their performance. There are three judges
and each may assign up to 10 points to each pair for a dance.
a) [15 marks] Use the sample data given on the facing page to produce an XML
file that will be valid with regard to the DTD given. Call the XML file
dancingCompetiton_15.xml.
b) [15 marks] Map the dancingCompetiton_15.dtd schema into an XML
Schema schema with no loss of any structuring information or constraints.
Call it dancingCompetiton_15.xsd. The dancingCompetiton_15.xml
should validate with dancingCompetiton_15.xsd. Use constraints of
ID/IDREF type in your dancingCompetiton_15.xsd.
SWEN432/Assignment 3
2
continued
Competitions
Competition
Competition Dance
@date = 10 June 2010
@dance_data = did_10
@pair_id = p7117
@pair_id = p3223
@dance_data = did_11
@pair_id = p7117
@pair_id = p3223
@date = 10 June 2011
@dance_data = did_11
@pair_id = p5775
@pair_id = p5555
@date = 24 June 2013
@dance_data = did_10
@pair_id = p7117
@pair_id = p3223
@dance_data = did_11
@pair_id = p7117
@pair_id = p3223
@pair_id = p5555
@dance_data = did_12
@pair_id = p7117
@pair_id = p3223
@pair_id = p5555
Pair
Competition Dance
Pair
Competition
Competition Dance
Pair
Competition
Competition Dance
Pair
Competition Dance
Pair
Competition Dance
Pair
@place = w
@score = 27.50
@score = 21.75
@score = 30.00
@score = 26.25
@place = a
@score = 28.75
@score = 23.05
@place = w
@score = 23.50
@score = 23.05
@score = 28.10
@score = 24.85
@score = 29.95
@score = 20.15
@score = 25.10
@score = 29.50
Pairs and Dancers
Pair
he_dancer
she_dancer
Pair
he_dancer
she_dancer
Pair
he_dancer
she_dancer
Pair
he_dancer
she_dancer
@pir_id = p7117
@dancer_id = d7007
@dancer_id = d1001
@pir_id = p3223
@dancer_id = d3003
@dancer_id = d2002
@pir_id = p5775
@dancer_id = d7007
@dancer_id = d5005
@pir_id = p5555
@dancer_id = d5005
@dancer_id = d0550
Name = James
Name = Anny
Address = Wellington
Address = Wellington
Name = Craig
Name = Anny
Address = Auckland
Address = Christchurch
Name = James
Name = Mimi
Address = Wellington
Address = Upper Hutt
Name = Paul
Name = Elaine
Address = Upper Hutt
Address = Masterton
Dance Data
Dance Details
Dance Details
Dance Details
Dance Details
Dance Details
Dance Details
@dance_id = did_10
@dance_id = did_11
@dance_id = did_12
@dance_id = did_13
@dance_id = did_14
@dance_id = did_15
@name = Tango
@name = Rumba
@name = Foxtrot
@name = Waltz
@name = Cha-Cha
@name = Quick Step
@category = Ballroom
@category = Latin
@category = Ballroom
@category = Ballroom
@category = Latin
@category = Ballroom
Venues
Place
@place_id = w
@city = Wellington
@address = 13 Capital City Street
@hall = Hall of Stars
Place
@place_id = a
@city = Auckland
@address = 13 Dancing Street
@hall = Great Dancing Hall
Place
@place_id = c
@city = Christchurch
@address = 13 Fred Aster Street
@hall = Judy Garland Hall
SWEN432/Assignment 3
3
continued
Question 2. Identity Constraints
[27 marks]
Use the dancingCompetiton_15.xsd schema you have produced in the
question 1 above to define the identity constraints. Change the type of all
ID/IDREF attributes to xsd:string. Call the new schema
dancingCompetiton_IC_15.xsd. The dancingCompetiton_IC_15.xsd
file should contain only identity constraints (no assert constraints).
Define:
a) [2 marks] A global key that will prevent appearance of duplicate
Competition elements. (For a global constraint, the scope is the whole
document.)
b) [2 marks] A global key that will prevent appearance of duplicate
Dance_Detail elements.
c) [2 marks] A global key that will prevent appearance of duplicate Place
elements.
d) [2 marks] A local key that will prevent appearance of duplicate
Competiton_Dance elements within the scope of a Competition element.
e) [4 marks] Two different local keys for the Pair element, both valid within the
scope of a Competiton_Dance element.
f) [2 marks] The attribute @dance_data of the Competition_Dance element
as a constraint referencing Dance_Details.
g) [2 marks] The attribute @place of the Competition element as a constraint
referencing the Place element.
h) [2 marks] A local key that will prevent appearance of duplicate he_dancer
elements within the scope of a Competition_Dance element.
i) [2 marks] A local key that will prevent appearance of duplicate she_dancer
elements within the scope of a Competition_Dance element.
j) [5 marks] There is a rule that a dancer is not allowed to change partners
during a whole dancing competition. Can you make a constraint to enforce that
rule? Justify your answer properly.
k) [2 marks] Make a constraint that will prevent dance scores to be erroneously
recorded as being greater than 30. Store it in a new .xsd file under the name
dancingCompetition_Assert_15.xsd.
Note: Do not alter your dancingCompetiton_15.xml file to force it satisfy
your integrity constraints.
SWEN432/Assignment 3
4
continued
Question 3. Comparing ID/IDREF and Identity Constraints
[18 marks]
In this question, you are asked to analyze, and discuss differences in checking
abilities of ID/IDREF mechanisms versus Identity Constraint and Assert
mechanisms. To answer the question, you will use the following files:
 dancingCompetiton_15.dtd,
 dancingCompetiton_IC_15.xsd, and
 dancingCompetiton_Assert_15.xsd.
For each constraint you have defined in question 2 above, discus the ability of
ID/IDREF mechanisms to achieve the same checking functionality.
Support your claims by introducing appropriate errors in a version of the XML
dancingCompetiton_15.xml file and possibly needed changes into the
dancingCompetiton_15.dtd file. In your answers, show what you have done
and achieved.
Question 4. Curriculum.xsd
[15 marks]
You are asked to make an XML Schema schema that will describe structure,
rules, and constraints on XML documents containing data about curricula. A
curriculum contains data about courses and their prerequisites. Prerequisites are
courses. A course may have no prerequisite, but there may be courses that have
many prerequisites. Also, a course may be not a prerequisite for any other
course, but there are courses that are prerequisite for many other courses.
There is an example curriculum document given on the course Assignments
page.
You may copy it in your own directory, and use it to test your XML Schema
schema. This document contains data about some of 100, 200, and 300 level
courses, and their prerequisites. Note, this is just an example curriculum
document. In the real life, a curriculum may have many more levels. Your task is
to make an XML Schema schema that will describe any number of course levels.
Also, the Curriculum.xml document should be valid according to your XML
Schema schema.
SWEN432/Assignment 3
5
continued
Question 5. Structural Constraints
[10 marks]
In this question, you are asked to deal with structural constraints.
Let A, B, C, D, and E be the element names. Use the syntax of XML Schema to
translate the following DTD:
<!
<!
<!
<!
<!
ELEMENT
ELEMENT
ELEMENT
ELEMENT
ELEMENT
E
D
A
B
C
(D)+>
(A | B | C | (A, B) | (A, C) | (B, C)) >
EMPTY>
EMPTY>
EMPTY>
into an XML Schema. Call your XML Schema
structuralConstraint_15.xsd. Implement it and test it.
Submission Instruction:
Submit all your files electronically (including all .xml, .dtd, and .xsd files you
have produced as answers to questions or you used for testing), so that Pavle
can test your files using xmllint or Xerces2 Java. Submit a printed version
of your answers in the SWEN432 hand-in box on the second floor of the Cotton
Building. Whenever appropriate, include the xmllint output produced by using
–noout option instead of a whole document.
Please do not submit any .odt, .zip, or similar files. Also, do not submit your files
in toll directory tries. All files in the same directory is just fine.
Also, please do not use weird .xmlns definitions in your XML Schema files. Use
just what we discussed in lectures.
SWEN432/Assignment 3
6
continued