CMPUT 499: Web-Based Information Systems

Assignment 5

CMPUT 499 (Winter 2002)

Due Date : March 25th, 2002 (in Lab)
Percentage overall grade: 4.5%
Penalties: 20% off a day for late assignments
Maximum Marks: 10

Objectives

  1. Get familiar with XML and DTD parsing, in particulat the DOM paradigm.
  2. Use existing XML parsers
  3. Display the content of an XML document with HTML
The goal of this assignment is to take an external XML file containing products information with a weekly special (in our case plants)and display them as a table in an HTML document.

1) The first task is to implement a simple form that allows to enter the path of an xml document. The interface could look like the following:
Input Form

The form, once submitted, would call a servlet that parses the xml document given as input and generate a table with the plants described in the XML document. Two XML files have been put on the course web site at:
http://www.cs.ualberta.ca/~zaiane/courses/cmput499/work/plants1.xml
http://www.cs.ualberta.ca/~zaiane/courses/cmput499/work/plants2.xml

2) Analyse the elements of the 2 given XML documents and produce the equivalent DTD.

3)Use a Java-based XML parser to parse and validate the XML file. Use a validating parser with DOM. I recommend to use the Xcerces-J parser from the Apache XML Project that you can find at http://xml.apache.org/xerces-j/index.html. Other parsers can be found here.Do not use a SAX parser for this assignment. After parsing the XML document, its content should be displayed in an HTML table such as in the following figures. If the xml file is invalid, an appropriate error message should be generated.
Output 1
Figure1: Table generated from plants1.xml


Output2
Figure2: Table generated from plants2.xml


You are asked to write a servlet that uses the parser to generate the HTML document. Some code samples can be found in the Appache XML project web site. Basically, to create a DOM XML parser you need to create a parser object:

DOMParser myParser = new DOMParser();
You can then parse an XML file with the parse() method:
myParser.parse ("http://www.cs.ualberta.ca/~zaiane/courses/cmput499/work/plants1.xml");
The getDocument() method from the DOMParser class returns the XML document in a tree format that can be traversed recursively. For instance
Document document = myParser.getDocument();
returns a tree with document being the root node, and methods such as getChildNodes() and getNodeType() return respectively a node list of children of a current node and the type of a node.

4) Provide another XML document that adheres to the DTD for our plnat example.

The deliverables are:

  1. A DTD file "plants.dtd" containing the DTD that plants1.xml and plants2.xml should adhere to.
  2. an XML file with plants data
  3. A URL to an on-line running application with the functionality as described.
  4. A short report explaining how you implemented the applications and the issues you noted. Remember that the esthetics are not important in this assignment. Functionality is important. Just stick to the example given in the above figures.
NOTE: The images for the plants are already provided. The images are accessible at the URL specified in the XML documents.

HOME     Activities