This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
 
GeeCON Prague 2014
 
subject: Reading a xml file