Java Reference
In-Depth Information
Demonstrating the SAX API
I'vecreateda SAXDemo applicationtodemonstratetheSAXAPI.Theapplicationcon-
sists of a SAXDemo entry-point class and a Handler subclass of DefaultHand-
ler2 . Listing 10-10 presents the source code to SAXDemo .
Listing 10-10. SAXDemo
import java.io.FileReader;
import java.io.IOException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
class SAXDemo
{
public static void main(String[] args)
{
if (args.length < 1 || args.length > 2)
{
System.err.println("usage: java SAXDemo xmlfile
[v]");
return;
}
try
{
XMLReader
xmlr
=
XMLReaderFact-
ory.createXMLReader();
if (args.length == 2 && args[1].equals("v"))
xmlr.setFeature("http://xml.org/sax/features/
validation", true);
xmlr.setFeature("http://xml.org/sax/features/
namespace-prefixes",
true);
Search WWH ::




Custom Search