Reputation: 1
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.
Upvotes: 0
Views: 2047
Reputation: 14044
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
Upvotes: 1