Rohit,
You have classpath problem.
I had the same problem, my test project has this classpath
parser.MyContentHandler
and the command I use to run the class SaxParserDemo is:
c:\..\theFolder where the contents.xml file is parser.MyContentHandler
contents.xml
first to run this make sure you have in the classpath all the classes you need
(use a batch fiele
to set within a dos shell session the classpath)
have fun with it
for anything you need drop me an e-mail
giuseppe
giuseppe laricchiuta
Bauer & Partner the business and technology group
Sch�tzenmattstrasse 266
Ch 8180 B�lach
tel.+41(0)1-86418-00
fax.+ 41(0)1-86418-44
www.bauer-partner.de
[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> Hey All,
> I was trying out a simple example from the book Java and XML(Brett
> McLaughlin), wherein i initiate the SAX parser by passing it a URI.
> Unfortunately, the org.xml.sax.Exception is generated whenever i run the
> program. The XML document exists in the same directory as the program. This is
> what i entered in the Command prompt window:
> C:\XML\XMLBooks\JavaXML\Chapter3\java SAXParserDemo contents.xml
> The java interpreter generated the following error:
> Error in parsing: File "file:///C:/XML/XMLBooks/JavaXML/Chapter3/contents.xml"
> not found.
>
> I tried using the complete pathname to the XML document but still got an
> error:
> C:\XML\XMLBooks\JavaXML\Chapter3\java SAXParserDemo
> C:\XML\XMLBooks\JavaXML\Chapter3\contents.xml
> ( Note : No Linebreak in actual command)
> I got the following error:
> Error in parsing: File "C:\XML\XMLBooks\JavaXML\Chapter3\contents.xml" not
> found.
>
> However, the exception is not generated when i hardcode the name of the file
> in
> the program as in:
> parser.parse("contents.xml");
>
> I appreciate and thanks in advance for any answers/suggestions.
>
> Here is the code i compiled (From the book : Java and XML by Brett
> McLaughlin):
>
> ______________________________________________________________________________________________
>
> // File : SAXParserDemo.java - Parse an XML file using SAX,
> // displaying callbacks in the parsing lifecycle.
>
> import java.io.IOException; // Exceptions that can result from loading XML
> Doc
>
> import org.xml.sax.SAXException; // Exceptions generated while parsing XML
> Doc.
>
> import org.xml.sax.XMLReader; // Interface for reading XML Docs using
> callbacks
> import org.apache.xerces.parsers.SAXParser; // Xerces implementation of
> XMLReader
>
> /* Function : SAXParserDemo
> * Instatiates the Parser.
> */
> public class SAXParserDemo
> {
> public void performDemo(String uri)
> {
> System.out.println("Parsing XML file: " + uri + "\n\n");
>
> try
> {
> // Instantiates a parser
> XMLReader parser = new SAXParser();
>
> // Parse the document
> parser.parse(uri);
> } catch (IOException e) {
> System.out.println("Error reading URI: " + e.getMessage());
> } catch (SAXException e) {
> System.out.println("Error in parsing: " + e.getMessage());
> }
>
> }
>
> public static void main(String[] args)
> {
> if (args.length != 1)
> {
> System.out.println("Usage: java SAXParserDemo [XML URI]");
> System.exit(0);
> }
>
> String uri = args[0];
> SAXParserDemo parserDemo = new SAXParserDemo();
> parserDemo.performDemo(uri);
> }
> }