import java.io.File;

import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import javax.swing.*;


/**
 * This is from CodeNotes for XML, by Gregory Brill, page 159.
 * I have made a few changes.
 */
public class PrintXmlNovel {

    public static void main(String args[]) throws Exception {

        // create a parser
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        SAXParser saxParser = spf.newSAXParser();
        XMLReader parser = saxParser.getXMLReader();

        // create a handler
        Handler handler = new Handler();

        // assign the handler to the parser
        parser.setContentHandler(handler);
        
        // get the file
        JFileChooser chooser = new JFileChooser();
        int result = chooser.showOpenDialog(null);
        if (result != JFileChooser.APPROVE_OPTION) {
            System.exit(1);
        }
        File file = chooser.getSelectedFile();

        // parse the document
        parser.parse(file.getCanonicalPath());
    }
}
