(: 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... XQuery Engine: Saxon :) (: 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> :)
the correct query result for that problem should be printed to standard output. Note: '-i' command in zorba for indenting the final output.zorba -i -f -q X.xq
Or,
java -cp saxon9he.jar net.sf.saxon.Query X.xq
perl runProblem.pl hw6.xq <problem#>
. This
script will parse the problem between (: Problem #1. :) and the next
(: Problem #2. :) (or EOF), dump that to tmp.xq and run it. One
drawback is that the error reported is with respect to tmp.xq
(ie line numbers are off).
Moreover, the output of the xquery should follow the DTD that is specified immediately after the problem statement. Furthermore, the output of the 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.
<!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 (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.
<!ELEMENT result (country)> <!ELEMENT country (name, state+)> <!ELEMENT state (name, population_ratio)> <!ELEMENT name (#PCDATA)> <!ELEMENT population_ratio (#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 (country+)> <!ELEMENT country (name, mountains+)> <!ELEMENT mountains (name, height)> <!ELEMENT height (#PCDATA)> <!ELEMENT name (#PCDATA)>
<!ELEMENT user (river+)> <!ELEMENT river (name, country*)> <!ELEMENT country (name)> <!ELEMENT name (#PCDATA)>(Note 1: some rivers may not have any country, due to noise in the data. It is OK to include these rivers, even if they look as they flow through no country at all.) Note 2: Use the
country
attribute for the
tag <river>
to find the respective
countries.