Solved

Cant read XML file

Posted on 2003-11-24
7
1,723 Views
Last Modified: 2006-11-17
I have a XML file which i put in the WEB-INF/CLASSES folder , but when i run my code that tries to read this xml file , Here is the snippet of the code.
************************************************
Document doc = XMLUtil.getDocument(new InputSource((new Object()).getClass().getResourceAsStream("/" + "Trial.xml")));
*************************************************
, it always looks for the file in my c:\program files\apache group\Tomcat 4.1 directory.....ultimately i will be running all code on UNIX and i wont have access to directories outside my web-app , so how do i solve this issue ?? Please help
0
Comment
Question by:rahulkothari
7 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 125 total points
ID: 9811801
Can't you do:

Document doc = XMLUtil.getDocument(new InputSource( getClass().getResourceAsStream( "/" + "Trial.xml" ) ) ) ;
0
 

Author Comment

by:rahulkothari
ID: 9811998
Nope doesnt work.....still looks in the same place
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9812009
hmmm...

what about if you put it in the same directory as the class you are in, then do something like:

Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "Trial.xml" ) ) ) ;

?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 86

Expert Comment

by:CEHJ
ID: 9812211
>>Nope doesnt work.....still looks in the same place

How do you know where it's looking?
0
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 9812406
As TimYates mentioned, remove the "/", just use the file name.

Thanks
Amit
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9813973
I guess putting it in the same directory as your classes is a simple way to do it.  I'd probably create a new folder under the WEB-INF folder (e.g. 'misc').  In the code, I'll call it this way:

Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "/misc/Trial.xml" ) ) ) ;
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9813989
Correction:  It should have read:
Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "/WEB-INF/misc/Trial.xml" ) ) ) ;

The reason I'll create the misc folder is that I don't wanna mix up my .class files with other files.

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 135
numbers ascending pyramid 101 196
JavaScript/Java - Changing an image background color 4 68
varialbe initialization 11 33
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question