(: this :)
.
For example, for the first question (Retrieve all the names of all cities located in Peru, sorted
alphabetically), your file should be:
We will run your XQuery files. Please make sure they run, by trying out commands like this:(: Name CSE 414 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
[80 points: 10 per question (8 for correct answer, 2 for following the DTD), plus 10 pts for the correct HTML file in problem 6]
Consider the XML data instance (the same dowloaded in setup) mondial.xml, available here (about 1.8 MB). Write XQueries to answer the following questions. You need to find out how various elements are nested, e.g. what is under a country, under which element is a city etc; for that inspect the mondial.dtd (ignore the warning that the data is not valid), or inspect mondial.xml directly. Your XQuery output should follow the associated DTD provided at each question. We will inspect visually if your output follows the DTD, except for problem 7, 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>The amount of white space does not matter.
For problem 7 you need to validate your results with the appropriate DTD using the w3 markup validator; instructions for how to use this validator are provided here.
<!ELEMENT result (country)> <!ELEMENT country (name, city+)> <!ELEMENT city (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 (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 | div | ol)*> <!ELEMENT ol (li+)> <!ELEMENT div (#PCDATA)>The idea with the <li> containing a div and ol tag is such that the output looks roughly like:
... <ul> <li> <div>River name</div> <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.