This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes sax Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "sax" Watch "sax" New topic


Francois Bourgault
Ranch Hand

Joined: Oct 30, 2001
Posts: 67
Hi all,
I have a class "xml_to_java". It is supposed to print out all the elements of "java_exam.xml". It is invoked from a servlet "trans_xml_java". I have the xml file in "/WEB-INF/" and both classes are in "WEB-INF/classes" Somehow I get the above io error. The only place where the class finds the xml file is when the xml file is in "jakarta-tomcat/bin". I also copied the file in the root of my application, but it doesn't work. Any idea what I'm doing wrong?
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
With tomcat the default file location is /bin directory, its not a good idea to place the work files under the bin directory - because not all servlet containers can read it.
My idea could be create a directory xmlfiles under web-inf and refer its location in web.xml file

<description>Default xml file location</description>

Now in ur servlet try to get this parameters with the following code
String xmlfileloc = getServletContext().getInitParameter("xmlfileloc");

Spritle Software Blogs
Francois Bourgault
Ranch Hand

Joined: Oct 30, 2001
Posts: 67
Hi Balaji,
Sorry about the late reply. What you mention still doesn't work. Even if I hardcode the path, tomcat can't find the file. Here's my setup in tomcat:
<webapps>/<my_appl>/source code
I use Tomcat 4.1.18 and I have the following code in xml_to_java.class
xml_nm = "\my_appl\xmlfiles\java_exam.xml";
XMLReader xr = XMLReaderFactory.createXMLReader( "org.apache.xerces.parsers.SAXParser" );
xr.setContentHandler( this );
xr.parse( new InputSource( new FileReader( xml_nm )) );
This won't work. The only xml file it reads is the one in the bin subdirectory.
What else am I missing in Tomcat setup?
subject: sax
It's not a secret anymore!