Narrandera, New South Wales, Australia, Google Earth image

ICT-4540 Homework 5


This exercise will allow you to explore XQuery as a mechanism to extract information from an XML document (or multiple XML documents), and create useful applications of the data

What to Hand In

For each problem, please hand in your XQuery file, the resulting output of running the query against the data source, and the display of your data in a browser.
Your resulting documents should be well-formed, and you should check them to be sure.


    For the required exercise, we are using a public-domain data set from Australia, the ToiletmapExport. The data can be found at http://data.gov.au/, and a copy of it has been placed in our course materials for reference. It is quite a large data set, and regenerated on a regular basis. This is a typical XML document for processing.

    All the other exercises are optional.

  1. Simple extraction
    1. Create a file called toilet.1.xquery to contain an XQuery to extract all the toilets in the Australian town of Narrandera, a picturesque place near the River Red Gum National Park, along the Murrumbidgee River.
    2. Run XQuery against the ToiletmapExport.xml dataset
    3. The result set should be in the root element <Toilets>.
      Each entry will be in an element <Toilet> under the <Toilets> element.
      You will need to handle namespaces from the Australian document.
      You will want to ensure that the result document has nicely formatted output.
      The Notes section adds some details to these instructions.
    4. Extract the following fields in the following order into each <Toilet> element: The attributes Latitude and Longitude are extracted into separate elements under this element (as an aside, in case you wanted them to remain attributes, attributes must be extracted first to be successfully inserted in XQuery), the Town, the State, the Country (which is always Australia), the Name, and the FacilityType
    5. Ensure your output is a well-formed document.
  2. Optional: More complex extraction
    1. The only thing that changes in this exercise from the previous one is the FLWOR expression.
    2. Instead of using the city of Narrandera as the anchor, instead, use its Latitude/Longitude to build a box 0.25 degree (about 15 miles) each direction from its center:
    3. Add a condition that either there must be a male and female accessible restroom, or an accessible unisex restroom.
    4. Proceed as above.
  3. Optional: Geographic context
    1. For either (or both) of the problem I or II solutions, make the output be valid KML
    2. Display your result file on Google Earth as your output.
  4. Optional: Multiple file manipulation
    1. This problem requires a copy of the USPresidents.xml and PresidentBirthdays.xml files in their original state.
    2. Goal: Create an XQuery to create the merged result document, where each President's birthday is inserted into the XML document in the correct location. The rest of these directions are a step-by-step recipe to accomplish this, if needed.
    3. Insert an XQuery comment for your name, class, date, and exercise number
    4. Set up copy-namespaces to no-preserve and inherit. When the problem is complete, you may want to see the result if you set to preserve.
    5. Set up the top-level element, presidents, and its end element, with a set of curly braces bracketing the content
    6. Set up two "let" statements; let $pres stand for the USPresidents.xml document, and $bd stand for the PresidentBirthdays.xml document.
    7. Set up a for loop letting $p stand for each of the president elements (presidents/president) in $pres
    8. Set up a let statement so $name will stand for the data content of the president's name
    9. Set up a let statement so $b will stand for the birthday element of the president such that the name equals $n
    10. Return the element president, with each of its subelements in a separate, curly-brace-enclosed statement (e.g., { $p/name }), inserting the birthday element, { $b }, in the right place
    11. You are ready to run the XQuery!
    12. Compare this result to what you did earlier. What are the anomalies? Which will be easier to maintain? Which was more work?
    13. Please submit your XQuery, the result, and answers to the questions in the previous step.



Criteria Weight
Simple Extraction: XQuery instructions 20%
Simple Extraction: root element and namespaces 30%
Simple Extraction: elements 30%
Simple Extraction: well-formed output document 20%
More complex extraction +10%
Geographic context +10%
Multiple File Integration +10%