permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Can any one help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Can any one help me" Watch "Can any one help me" New topic

Can any one help me

sravan mandala

Joined: Mar 13, 2001
Posts: 7
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.*;
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 );
} catch (Exception e) {
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 (SAXException e1) {
System.out.println("the messageis:"+e1.getMessage());

catch ( Exception e ) {

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
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="" TARGET=_blank rel="nofollow">JSP: The Complete Reference</A><BR><A HREF="" TARGET=_blank rel="nofollow">Instant Java Servlets</A>
I agree. Here's the link:
subject: Can any one help me
Similar Threads
Xml Parsing
why we need to specify DefaultHandler methods in DefaultHandler block in sax
XML as calculator input
XML handler --> populate Hashmap
using abstract method and class