Programming Assignment #7
Using XQuery

Due on Tuesday November 25 before midnight.


The purpose of this project is to learn XQuery.

This project must be done individually. No copying is permitted. Note: We will use a system for detecting software plagiarism, called Moss, which is an automatic system for determining the similarity of programs. That is, your program will be compared with the programs of the other students in class as well as with the programs submitted in previous years. This program will find similarities even if you rename variables, move code, change code structure, etc.

Note that, if you use a Search Engine to find similar programs on the web, we will find these programs too. So don't do it because you will get caught and you will get an F in the course (this is cheating). Don't look for code to use for your project on the web or from other students (current or past). Don't try to hire a freelancer to do the coding for you. Just do your project alone using the help given in this project description and from your instructor and GTA only.


You will do this project on your own PC/laptop. You will use Zorba, which is a free implementation of XQuery.

Put all XQueries in a file "queries.xq" and use the Zorba Command Line Utility to evaluate the XQueries.

Note 16/11/2014: If you are using Ubuntu 14.04, you first need to download one of libicu48*.deb from and do sudo dpkg -i libicu48*.deb.


The following provide some tutorials. Use them as a reference only.

Project Requirements

Write a sample XML file, travel.xml, for flight reservations that satisfies the following DTD:

<!ELEMENT travel (airport | flight | passenger | reservation)*>
<!ELEMENT airport (name)>
    <!ATTLIST airport code ID #REQUIRED>
<!ELEMENT flight (date,departureTime,arrivalTime)>
    <!ATTLIST flight id ID  #REQUIRED
                     from IDRef #REQUIRED    <!-- the code of the departure airport -->
                     to IDRef #REQUIRED>     <!-- the code of the destination airport -->
<!ELEMENT passenger (name,address)>
    <!ATTLIST passenger ssn ID #REQUIRED>
<!ELEMENT reservation (creditcard)>
    <!ATTLIST reservation passenger IDRef #REQUIRED        <!-- the passenger ssn -->
                          flight IDRef #REQUIRED>          <!-- the flight id -->
where all other elements are PCDATA. Express the following queries using XQuery and run them against your file travel.xml using Zorba:
  1. Print flight information about all flights that depart from DFW and arrive at JFK on 11/20/2014.
  2. For each passenger, print her name and address, and the total number of her reservations.
  3. For each airport, print the airport code and name, the total number of departing flighs, and the total number of arriving flights.
  4. For each flight that departs from DFW, print the flight date, the departure and arrival airport codes, the departure and arrival times, and the total number of reservations for this flight.
  5. Print the total number of reservations made for the passenger John Smith.
  6. Print all the flight destinations for the passenger John Smith.
You should write the file travel.xml so that your queries return a non-empty result.

What to Submit

Use the form below to submit your XML and XQuery files (or you may zip all files and submit the zipped file).

Submit Project #7:

Last modified: 11/11/14 by Leonidas Fegaras