Hi,
I was trying a sample XML Parser program using
java with using jaxp1.1 and SAX2.0 software.I created a class "sampClass1" which simply counts the number of specific tags of a input XML file.It clean compiled(no errors/warnings).But when am executing the following is the error message i got
C:\>java sampClass1
Exception in
thread "main" java.lang.NoClassDefFoundError: sampClass1
Following is the code.
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.Locator;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
//import org.apache.xerces.parsers.SAXParser;
public class sampClass1 extends DefaultHandler
{
private int count = 0;
public static void main(
String args[]) throws Exception
{
sampClass1 c1 = new sampClass1();
c1.bookCounter();
}
public void bookCounter() throws Exception
{
XMLReader xmlreader = null;
SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setValidating(false);
SAXParser spParser = spFactory.newSAXParser();
xmlreader = spParser.getXMLReader();
xmlreader.setContentHandler(this);
InputSource source = new InputSource("samp.xml");
xmlreader.parse(source);
//xmlreader.parse("file:///C:/samp.xml");
}
public void startElement(String name , Attributes atts) throws SAXException
{
if(name.equals("book"))
count++;
}
public void endDocument() throws SAXException
{
System.out.println("There are "+count+" books");
}
}
Please respond.
Thanks and Regards,
Muru.