(: this :).
For example, the first question is:
(1) Retrieve all the names of all cities located in Peru, sorted
alphabetically.
(: Name
CSEP 544
Other metadata...
:)
(: Problem 1. :)
(Insert your XQuery here)
(: Results
<result>
<country>
<name>Peru</name>
<city>
<name>Abancay</name>
</city>
<city>
<name>Arequipa</name>
</city>
<city>
<name>Ayacucho</name>
</city>
...
</country>
</result>
:)
java -cp saxon9he.jar net.sf.saxon.Query ProblemX.xq
the correct query result for problem X should be printed to
standard output.
Moreover, the output of the xquery should follow the associated DTD provided after each question. We will inspect visually if your output follows the DTD, except for problem 9, where we will validate your output automatically. Furthermore, the output of each xquery should be a well formed XML after standard XML headers (<?xml version="1.0" encoding="UTF-8" ?>, etc) have been added. That is, the output of the first question should be (along the lines of):
<result>
<country>
<name>Peru</name>
<city>
<name>Abancay</name>
</city>
<city>
<name>Arequipa</name>
</city>
<city>
<name>Ayacucho</name>
</city>
...
</country>
</result>
Note: The amount of white space does not matter.
To test your results to ensure that they are well-formed or that they follow the appropriate DTD, you can use the w3 markup validator. Instructions for how to use this validator are provided here. You must perform this validation for problem 9, the others are optional.
<!ELEMENT result (country)> <!ELEMENT country (name, city+)> <!ELEMENT city (name)> <!ELEMENT name (#PCDATA)>
<!ELEMENT result (country)> <!ELEMENT country (name, province+)> <!ELEMENT province (name, capital)> <!ELEMENT capital (name)> <!ELEMENT name (#PCDATA)>
<!ELEMENT result (country*)> <!ELEMENT country (name)> <!ATTLIST country num_provinces CDATA #REQUIRED> <!ELEMENT name (#PCDATA)>
<!ELEMENT result (country)> <!ELEMENT country (name, state+)> <!ELEMENT state (name, population_density)> <!ELEMENT name (#PCDATA)> <!ELEMENT population_density (#PCDATA)>
<!ELEMENT result (ethnicgroups+)> <!ELEMENT ethnicgroups (name)> <!ATTLIST ethnicgroups num_countries CDATA #REQUIRED> <!ELEMENT name (#PCDATA)>
<!ELEMENT result (country)> <!ELEMENT country (name, state+)> <!ELEMENT state (name, population_ratio)> <!ELEMENT name (#PCDATA)> <!ELEMENT population_ratio (#PCDATA)>
<!ELEMENT result (country+)> <!ELEMENT country (name, mountains+)> <!ELEMENT mountains (name, height)> <!ELEMENT height (#PCDATA)> <!ELEMENT name (#PCDATA)>
<!ELEMENT html (head, body)> <!ELEMENT head (title)> <!ELEMENT title (#PCDATA)> <!ELEMENT body (h1, ul)> <!ELEMENT h1 (#PCDATA)> <!ELEMENT ul (li+)> <!ELEMENT li (#PCDATA | font | ol)*> <!ELEMENT ol (li+)> <!ELEMENT font (#PCDATA)>The idea with the <li> containing a font and ol tag is such that the output looks roughly like:
...
<ul>
<li>
<font>River name</font>
<ol>
<li>Country crossed #1</li>
<li>Country crossed #2</li>
...
</ol>
</li>
...
</ul>
Note: Use the country attribute for the
tag <river> to find the respective
countries.
<!ELEMENT result (waterbody)> <!ELEMENT waterbody (name, adjacent_countries+)> <!ELEMENT adjacent_countries (country+)> <!ELEMENT country (name)> <!ELEMENT name (#PCDATA)>Note: Use the
country attribute for the
tag <sea> to find the respective
countries.