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.
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
You can also use SAX parser to read XML file . Go through this link
will help you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.