Assignment 5CMPUT 499 (Winter 2002)
Due Date : March 25th, 2002 (in Lab)
Objectives
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:
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: 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. 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:
| |
![]() ![]() |
---|