Programming Assignment 6
Using SAX and DOM

Due on Thursday April 2 before midnight


This project must be done individually. No copying is permitted. The goal of this project is to learn the SAX and DOM XML APIs.


You will do this project on your own PC/laptop. You may use a text editor to develop your Java programs but you can also use Netbeans.

Here are some examples:


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

Project Requirements

  1. Write a Java function
    void toSAX ( Node x, PrintHandler h )
    that converts a DOM node x and its descendants into a SAX stream, which is fed into the SAX handler h. The PrintHandler, which extends the SAX DefaultHandler, has SAX event handlers to print the SAX stream (see page 18 of the slides on XML tools). Use this function to print an entire XML document.
  2. Write a SAX handler in Java that parses an XML document using a SAX parser, and constructs the DOM tree of the document. Then the resulting DOM tree from this handler should be printed to the output using a DOM printer. Hint: There is a method to access the parent of a node in DOM. You may use it when you close an XML element.
You don't have to handle element attributes. Put everything in one Java file. Your Java program should run against the file cs.xml (which must be in the same directory), and should not have any arguments.

What to Submit

Use the form below to submit your java files.

Submit this file:

Last modified: 03/25/09 by Leonidas Fegaras