That lets us override the methods we care about and default the rest.Since we're going to run it standalone, we need a main method.And we need command-line arguments so we can tell the app which file to echo. SAXParser; public class Echo extends Handler Base { ...

validating sax parser call first-8validating sax parser call first-18validating sax parser call first-79

In real life, you are going to have little need to echo an XML file with a SAX parser.

Usually, you'll want to process the data in some way in order to do something useful with it.

(If you want to echo it, it's easier to build a DOM tree and use its built-in printing functions.) But echoing an XML structure is a great way to se the SAX parser in action.

In this exercise, you'll set echo SAX parser events to , which implements all of the interfaces we discussed in An Overview of the Java XML APIs.

The SAXParser Factory class creates the instance we use.

It throws a Parser Configuration Exception if it is unable to produce a parser that matches the specified configuration of options.(You'll see more about the configuration options later.) Finally, the SAXParser is what the factory returns for parsing.The first order of business is to process the command line argument, get the name of the file to echo, and set up the output stream.Add the text highlighted below to take care of those tasks and do a bit of additional housekeeping: public static void main (String argv []) { if (argv.length != 1) { println ("Usage: cmd filename"); (1); } try { // Set up output stream out = new Output Stream Writer (System.out, "UTF8"); } catch (Throwable t) { t.print Stack Trace (); } (0); } static private Writer out; When we create the output stream writer, we are selecting the UTF-8 character encoding.We could also have chosen US-ASCII, or UTF-16, which the Java platform also supports.