0

I need to know how I can read a xml file which is placed at web.war. This also needs to be server independent.

Appreciate your help.

Thank you.

2 Answers 2

1

just read it using the usual suspects from java.io , and parse it using JAXP (Java API for XML Processing, it comes bundled with java since v. 1.4) .

JAXP is quite extensive and flexible, and provides quite a few different ways of accomplishing what you want. A straight forward way is to use the DOM XML parser.

Look here for a example of how you use that

http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

UPDATED

To answer the question in you comment, if you need the path to a file which lies somewhere within the context of the web application, look into ServletContext (more specifically, the getContextPath() method)

http://docs.oracle.com/javaee/5/api/javax/servlet/ServletContext.html

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Thanks for the reply. I can read it using either sax parser or dom parser but the issue is to get the path irrespective of the web server. for ex. in jboss i need to put the xml under deploy folder where in tomcat i need to put it under webapps folder. how can i get the path to that file ?
0

You can also use SAX parser to read XML file . Go through this link

will help you.

1 Comment

Hi Thanks for the reply. I can read it using either sax parser or dom parser but the issue is to get the path irrespective of the web server. for ex. in jboss i need to put the xml under deploy folder where in tomcat i need to put it under webapps folder. how can i get the path to that file ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.