trying to parse a file with SAX

Hi All,

I have some code which takes a XML DTD and parses it, writing information to System.out. Or it's meant to - I cannot get the parser to see the DTD file.

The code is:

public static void main (String[] args)

{

try

{

Class loadedClass = Class.forName("com.ibm.xml.parser.SAXDriver");

Parser xParser = (Parser)loadedClass.newInstance();

CatalogueReader cr = new CatalogueReader();

xParser.setDocumentHandler(cr);

xParser.setErrorHandler(cr);

xParser.parse("catalogue1.txt");

}

catch(Exception e)

{System.out.println("Problem: " +e.getMessage());}

}

which produces the following message:

Problem: catalogue1.txt (The system cannot find the file specified)

I have added the text file to the project and tried putting it in various folders without success.

I've been stuuck on this for a day now and would appreciate a nudge in the right direction.

Many thanks.

[1002 byte] By [November999a] at [2007-11-27 8:27:06]
# 1
It appears com.ibm.xml.parser.SAXDriver is an interface and not an object that you can instansiate. You'll need to locate some object that implements the interface before using Class.forName().
George123a at 2007-7-12 20:16:47 > top of Java-index,Desktop,Developing for the Desktop...
# 2

You might try creating a separate class and putting all your code in that class's constructor and seeing if that works. (have main() instansiate that class in order to run the code). I try to avoid putting code that parses directly in main(). You can also add the following to your main() and / or class's constructor to see what directory its is running from:

File file=new File("");

System.out.println(file.getAbsolutePath());

Lets say your catalogue1.txt file is two directories 'up' from the path given from getAbsolutePath() above, and one level down in a package called 'books', then this

might work:

xParser.parse("../../books/catalogue1.txt");

or

xParser.parse("././books/catalogue1.txt");

George123a at 2007-7-12 20:16:47 > top of Java-index,Desktop,Developing for the Desktop...