| CIT
597 Assignment
3: SAX Printer
Fall 2006, David Matuszek |
Formatter. Use a validating SAX parser to read in your XML file from the previous assignment. Display it with the tag and attribute information in one column and the content in another.
| Input XML | Output (on screen) | ||
|---|---|---|---|
<?xml version="1.0"?> <novel> <title> In the Dark </title> <foreword> <paragraph> This is the great American novel. </paragraph> </foreword> <chapter number="1"> <paragraph> It was a dark and stormy night. </paragraph> <paragraph> Suddenly, a shot rang out! </paragraph> </chapter> </novel> |
|
Use Swing to put a basic GUI on the screen. It need only consist of a button
or menu item to click in order to choose a file, and a large scrollable text
area in which to display the result. Use a JFileChooser to choose
the file to be read. (If you need help with Swing, see my SwingExamples.jar program.)
Use SAX to read in an XML file, and display it as in the example above.
java.util.Formatter to create your strings for display.
(Hint: Try it out in a simple little test program before using it "for
real" in your assignment.) "In
the Dark" is under both <novel> and <title>, so should be indented less than "This
is the great American novel." which is under three things, <novel>, <foreword>,
and <paragraph>.If necessary, you may make minor changes to your XML and DTD. For example, if you have any mixed content, eliminate it. If you did not use any attributes, add some.