CSE 794R/ECE 694R
LAB #7: XML -- Phone Book Services


Due: 9:30 am, Tuesday, June 6

Overview

In this assignment, you will work with a collection of assigned phone numbers stored in an XML document. You will use various XML technologies to perform certain tasks:

  1. a DTD for defining valid phone book xml documents
  2. an XSLT description for creating an HTML view of the phone book
  3. a SAX application to answer simple queries on the phone book data.

Part 1: DTD

Write a DTD to define the structure of an XML document representing the information stored by the phone company for a client. Your DTD should support the following aspects:

  1. A client can have a single name, a first and last name, or a first name, last name, and (potentially multiple) middle names.
  2. A client has a single address, but can have several numbers.
  3. A client need not have a recorded address.
  4. Each client must have a unique customer identifier, and is designated either as a business or as an individual.
  5. A client may optionally be designated as "unlisted" (meaning they will not appear in any listing); by default clients are included in listings.
  6. An address (if given) may optionally be designated as "private".

You may find it helpful to develop the DTD along with an example XML document of the desired type. The most convenient way to do this is by embedding the DTD definition directly in the header of the document. That is, you can write something like:

<?xml version="1.0"?>
<!DOCUMENT phone_book [
    <!ELEMENT ...  etc ... >
    <!ATTLIST ...  etc ... >
]>

<!-- your xml document goes here -->

This way you can gradually refine your DTD, as you extend and expand your example. Validate your document as you go, possibly by using an online XML document validator (e.g., http://www.stg.brown.edu/service/xmlvalid/).

Be sure your final submission of your DTD is as a separate document, however, not embedded in some example XML document.

Part 2: XSLT

Use XSLT to create an HTML page from a phone book XML document (conformant to your DTD from Part 1). The resulting HTML document should have (at least) the following features:

  1. A heading "Phone Book Listing".
  2. A table, with borders, containing the listing data (names, addresses, and numbers only).
  3. Each row of the table should correspond to a single customer.
  4. Unlisted customers should not appear.
  5. A private address should not appear.

You should use the Xalan XSLT processor, installed at /class/sce/local/xalan. The documentation for this processor can be found at http://xml.apache.org/xalan-j/getstarted.html. There are some useful examples under the installation directory.

The HTML should be generated by running xalan.xslt.Process directly (however, you can also use the xml-stylesheet processing instruction within the document itself). For example, we expect to run:

setenv XALAN_ROOT /class/sce/local/xalan
setenv XALAN_PATH {$XALAN_ROOT}/xalan.jar:{$XALAN_ROOT}/serializer.jar:{$XALAN_ROOT}/xml-apis.jar:{$XALAN_ROOT}/xercesImpl.jar
java -cp $XALAN_PATH org.apache.xalan.xslt.Process -in book.xml -xsl phone_book.xsl -out book.html

Part 3: SAX

Write a Java application for phone number look-up. Your application should run from the command line, taking a single argument: the name of the XML document containing the customer data. Your application should support both lookup and reverse lookup functionality. For the former, the user should be prompted to enter a target last name and the application should retrieve the corresponding number(s). For the latter, the user should be prompted to enter a target number and the application should retrieve the corresponding last name. For simplicity, your application can ignore the "unlisted" aspect of customer data (ie treat all customer entries as retrievable).

Your application should use the SAX API, as provided by the Xerces XML parser, installed at /class/sce/local/xerces. The documentation for this parser can be found at http://xerces.apache.org/xerces2-j/. There are some useful examples under the installation directory.

You will probably compile your program with something like the following:

setenv XERCES_ROOT /class/sce/local/xerces
setenv XERCES_PATH {$XERCES_ROOT}/xml-apis.jar:{$XERCES_ROOT}/xercesImpl.jar
javac -cp .:{$XERCES_PATH} Finder.java

And run the program with:

java -cp .:{$XERCES_PATH} Finder book.xml

What to turn in

You should submit the following:

  1. An XML document, named book.xml, representing the phone customer databases. Your example document should be large and varied enough to adequately illustrate all the aspects of its DTD.
  2. The DTD from Part 1, named phone_book.dtd.
  3. The XSLT document from Part 2, named phone_listing.xsl.
  4. Your Java program from Part 3.
  5. A readme file, named README, detailing how to compile and run your Java SAX program.

Submit all your files with the usual command:

    submit c794aa lab7 book.xml phone_book.dtd phone_listing.xsl ...

No hard-copy submission is required.