• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to acces xml document

 
Harry Pattern
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I just recently created a program that will read an xml document and parse contents then display on the web page . the program segment contains something like this.
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser parser=factory.newSAXParser();
parser.parse("webconfig.xml",this);
I successfully load the contents if I specify the complete path of the xml document. What I need is to specify that the xml document is on the same directory as my class, or I need to specify the current directory. Im running tomcat4 on a linux server. The path should be in linux.
Kindly help me on this.
Thanks
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Harry,
I assume you are using either Servlets or JSP that contains the parser to parse the XML document, as you said you are using Tomcat.
First of all, while you provide the full path, it always works becos the container can locate the file in the file system.
The default path (current path) for the JSP is the directory that the "compiled" JSP located, and thus, if you want to use relative path, you always need to refer to that directory.
Otherwise, since the home directory of JSP/Servlet is usually
$CATALINE_HOME/your_app_name
Thus, the document root of the application is $CATALINE_HOME/your_app_name, if you have put a XML file, say abc.xml, at $CATALINE_HOME/your_app_name/abc.xml, you can access it by providing the path /abc.xml, which is relative to the document root.
Hope this help.
Nick.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check out ServletContext.getRealPath().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!