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);
     }
}


Reply via email to