Hi , I am using a Sax2.0 api for parsing an xml file and source code of that is import org.xml.sax.*; import org.xml.sax.helpers.*; import java.io.*; public class Example1 extends DefaultHandler {
// Override methods of the DefaultHandler class // to gain notification of SAX Events. // // See org.xml.sax.ContentHandler for all available events. // public void startDocument( ) throws SAXException { System.out.println( "SAX Event: START DOCUMENT" ); } public void endDocument( ) throws SAXException { System.out.println( "SAX Event: END DOCUMENT" ); } public void startElement( String namespaceURI, String localName, String qName, Attributes attr ) throws SAXException { System.out.println( "SAX Event: START ELEMENT[ " + localName + " ]" ); // Also, let's print the attributes if // there are any... for ( int i = 0; i < attr.getLength(); i++ ){ System.out.println( " ATTRIBUTE: " + attr.getLocalName(i) + " VALUE: " + attr.getValue(i) ); } } public void endElement( String namespaceURI, String localName, String qName ) throws SAXException { System.out.println( "SAX Event: END ELEMENT[ " + localName + " ]" ); } public void characters( char[] ch, int start, int length ) throws SAXException { System.out.print( "SAX Event: CHARACTERS[ " ); try { OutputStreamWriter outw = new OutputStreamWriter(System.out); outw.write( ch, start,length ); outw.flush(); } catch (Exception e) { e.printStackTrace(); } System.out.println( " ]" ); }
public static void main( String[] argv ){ System.out.println( "Example1 SAX Events:" ); try { // Create SAX 2 parser... XMLReader xr = XMLReaderFactory.createXMLReader(); // Set the ContentHandler... xr.setContentHandler( new Example1() ); // Parse the file... xr.parse( new InputSource( new FileReader( "Example1.xml" )) );
catch ( Exception e ) { e.printStackTrace(); } } }
and when i run the above example with giving a .xml file as argument its giving the following error can anyoone tell me what the error could be and how to solve it Exception is : org.xml.sax.driver not specified but i dont find any class by name driver in the package please tell me
Phil Hanna
Ranch Hand
Joined: Apr 05, 2001
Posts: 118
posted
0
Either specify a system property named "org.xml.sax.driver" with a value of "org.apache.xerces.parsers.SAXParser", or change this line: XMLReader xr = XMLReaderFactory.createXMLReader(); to this: XMLReader xr = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
Phil Hanna<BR>Sun Certified Programmer for the Java 2 Platform<BR>Author of :<BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072127686/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="http://www.amazon.com/exec/obidos/ASIN/0072124253/electricporkchop/107-3548162-1137317" TARGET=_blank rel="nofollow">Instant Java Servlets</A>