Homework 2

Consider the XML data instance Mondial, avaialable here (at the bottom of the page). Write XQueries to answer the following questions. In formulating your questions, you need to understand how various elements are nested: e.g. what is under a country, under which element is a city etc. For that it helps if you inspect the DTD (ignore the warning that the data is not valid), or inspect the data directly. For each question below turn in the XQuery, and the result of running the query on the XML data (which should be an XML document).

  1. Retrieve all the names of all cities located in Peru, sorted alphabetically.
  2. Find all countries with more than 20 provinces.
  3. Find all ethnic groups that live in more than more than 10 countries.
  4. Find the countries adjacent to the 'Pacific Ocean' sea.
  5. Find the names of all countries that have at least 3 mountains over 2000m high, and list the names and heights of all mountains in these countries (regardless of their height). Note: the height attribute is in meters, so you don' have to do any conversions.
  6. One user is interested in long rivers. Produce the following view of the data, containing only rivers longer than 2000 (all units are in km), in the format described below:
  7. For each province of China, return its capital. Order the result by province name.
  8. For each province(state) in the United States, compute the ratio of its population to area, and return each province's name, its computed ratio, and order them by ratio.
  9. Find all the provinces(states) of  the United States with population more than 11,000,000. Compute the ratio of each qualified state's population to the whole popolution of the country. Return each state's name and the ratio. Order by the ratio in descending order.
  10. For each river which crosses at least 2 countries, return its name, and the names of the countries it crosses. Order by the numbers of countries crossed.

For this question you need to run galax, which you can download from here. This is what an input file for the galax executable will look like.

Due Date: Apr 19. Email your solutions to Bhushan.

The Sample Solution is now available.