[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Problems with setting up Xerces


setting up xerces
Hi everyone =)

I wrote a simple parser for xml using SAX. there is no
problem at compilation time. when i run the program
however, the following error is generated:

Exception in thread "main"
java.lang.NoClassDefFoundError:
org/xml/sax/helpers/DefaultHandler
        at java.lang.ClassLoader.defineClass0(Native
Method)
        at java.lang.ClassLoader.defineClass(Unknown
Source)
        at
java.security.SecureClassLoader.defineClass(Unknown
Source)
        at java.net.URLClassLoader.defineClass(Unknown
Source)
        at java.net.URLClassLoader.access$100(Unknown
Source)
        at java.net.URLClassLoader$1.run(Unknown
Source)
        at
java.security.AccessController.doPrivileged(Native
Method)
        at java.net.URLClassLoader.findClass(Unknown
Source)
        at java.lang.ClassLoader.loadClass(Unknown
Source)
        at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
        at java.lang.ClassLoader.loadClass(Unknown
Source)
        at
java.lang.ClassLoader.loadClassInternal(Unknown
Source)


If there's anyone who can provide me with some clues
to what this error is, thank you so much beccause i've
been working on it for a week and have followed the
installation in setting classpath. have even tried to
install it as an extension to java. none of it work.

here is my java source code. Please enlighten me on
any semantic errors that might have caused the runtime
error.

Thank you so much folks!!


import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

public class Echo extends DefaultHandler
{	private static Writer out;
	
	public static void main(String[] args)
	{
		if(args.length != 1) {
			System.out.println("Usage: cmd filename");
			System.exit(1);
		}
				
		//use an instance of ourselves as an SAX event
handler
		DefaultHandler handler = new Echo();
		
		//use the default(non-validating) parser
		SAXParserFactory factory =
SAXParserFactory.newInstance();
				
		try {
			//set up output stream	
			out = new OutputStreamWriter(System.out, "UTF8");
			
			//parse the input
			SAXParser saxParser = factory.newSAXParser();
			saxParser.parse(new File(args[0]), handler);							
				
		} catch(Throwable t) {
			t.printStackTrace();
		}
		
		System.exit(0);
	}
	
	private void emit(String s) throws SAXException
	{
		try {
			out.write(s);
			out.flush();
		} catch(IOException e) {
			throw new SAXException("IO Error", e);
		}
	}
	
	private void nl() throws SAXException
	{
		String lineEnd =
System.getProperty("line.seperator");
			
		try {
			out.write(lineEnd);
		} catch(IOException e) {
			throw new SAXException("IO Error", e);
		}
	}
	
	public void startDocument() throws SAXException
	{
		emit("<?xml version='1.0' encoding='UTF-8'?>");
		nl();
	}
	
	public void endDocument() throws SAXException
	{
		try {
			nl();
			out.flush();
		} catch(IOException e) {
			throw new SAXException("IO Error", e);
		}
	}
	
	public void startElement(String namespaceURI, String
sName, String qName,
							 Attributes attrs)
	throws SAXException
	{
		String eName = sName;
		if("".equals(eName))	//qualified name
			eName = qName;
		
		emit("<" + eName);
		if(attrs != null) {
			for(int i = 0; i < attrs.getLength(); i++) {
				String aName = attrs.getLocalName(i);	//attribute
name
				if("".equals(aName))
					aName = attrs.getQName(i);
				emit(" ");
				emit(aName + "=\"" + attrs.getValue(i) + "\"");
			}
		}
		emit(">");
	}
	
	public void endElement(String namespaceURI, String
sName, String qName)
	throws SAXException
	{
		emit("<" + sName + ">");
	}
	
	public void characters(char buf[], int offset, int
len) throws SAXException
	{
		String s = new String(buf, offset, len);
		emit(s);
	}
}	

rgds,
Javier

__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Beat the crowds!  Do your X'mas Shopping Online!
http://shopping.yahoo.com.sg/

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.