File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Reading a xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reading a xml file" Watch "Reading a xml file" New topic
Author

Reading a xml file

Renata fonseca
Ranch Hand

Joined: Mar 15, 2002
Posts: 48
I just want to read a xml file located in the same path of my servlet... I�d like to use a relative path to find and open the file...
I�ve tried like this:
--- SimpleServlet.java ---
SAXBuilder b = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
Document configXml = b.build(SimpleServlet.class.getResourceAsStream("/config.xml"));
---
it returned an error:
---
org.jdom.JDOMException: Error on line 0: File "" not found.
---
please help me!
Renata fonseca
Ranch Hand

Joined: Mar 15, 2002
Posts: 48
ops, sorry...
actually the xml file is located at app dir (the jsp and html file directory)... how can I found the xml file in that directory?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
getServletContext().getRealPath("")
give you actual path example
C:\Tomcat\webapps\urprojectname\
Now its upto you put files according ur needs.
Hope this helps.

Originally posted by Renata fonseca:
ops, sorry...
actually the xml file is located at app dir (the jsp and html file directory)... how can I found the xml file in that directory?


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading a xml file
 
Similar Threads
FileNotFound by SAXBuilder
building error when validating against schema using jdom
jar packaging
Reading external xml files from a jar
org.jdom.JDOMException: Error on line -1: Premature end of file.