简体   繁体   English

从Web服务器读取XML文件

[英]Read XML file from a web server

I need to know how I can read a xml file which is placed at web.war. 我需要知道如何读取放置在web.war中的xml文件。 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) . 只需使用java.io中常见的可疑对象读取它,然后使用JAXP(用于XML处理的Java API,从1.4版开始就与Java捆绑在一起)进行解析。

JAXP is quite extensive and flexible, and provides quite a few different ways of accomplishing what you want. JAXP相当广泛且灵活,并提供了许多不同的方式来完成您想要的。 A straight forward way is to use the DOM XML parser. 直接的方法是使用DOM XML解析器。

Look here for a example of how you use that 在这里查看如何使用该示例

http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/ 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) 为了回答您所评论的问题,如果您需要文件的路径位于Web应用程序上下文中的某个位置,请查看ServletContext(更具体地说,是getContextPath()方法)

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

You can also use SAX parser to read XML file . 您还可以使用SAX解析器读取XML文件。 Go through this link 通过此链接

will help you. 会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM