1 package org.xml.sax.demo;
2 // SAX demonstration for parsing from a raw byte stream.
3 // No warranty; no copyright -- use this as you will.
4 // $Id: ByteStreamDemo.java,v 1.4 1998/05/01 20:38:19 david Exp $
6 import org.xml.sax.Parser;
7 import org.xml.sax.InputSource;
8 import org.xml.sax.SAXException;
10 import org.xml.sax.helpers.ParserFactory;
12 import java.io.FileInputStream;
17 * Demonstrate parsing from a byte stream.
19 * <p>Usage: java -Dorg.xml.sax.parser=<var>CLASSNAME</var> ByteStreamDemo
22 * <p>The SAX parser will open a byte stream to the file name
23 * provided. Note the use of the InputStreamAdapter class to allow a
24 * Java InputStream to serve as a SAX ByteStream.</p>
28 public class ByteStreamDemo {
34 public static void main (String args[])
40 FileInputStream input;
42 // First, check the command-line usage.
43 if (args.length != 1) {
44 System.err.println("Usage: java -Dorg.xml.sax.parser=<classname> " +
45 "SystemIdDemo <document>");
49 // Allocate a SAX Parser object, using
50 // the class name provided in the
51 // org.xml.sax.parser property.
52 parser = ParserFactory.makeParser();
54 // Allocate an event handler, and register
55 // it with the SAX parser for all four
56 // types of events (we could use a
57 // separate object for each).
58 handler = new DemoHandler();
59 parser.setEntityResolver(handler);
60 parser.setDTDHandler(handler);
61 parser.setDocumentHandler(handler);
62 parser.setErrorHandler(handler);
64 // Create a Java FileInputStream from
65 // the file: note that SAX cannot
67 input = new FileInputStream(args[0]);
69 // Create the input source.
70 source = new InputSource(input);
71 source.setSystemId(args[0]);
73 // Parse the document from the