如何用Java读取XML文件? [英] How to read an XML file with Java?

查看:78
本文介绍了如何用Java读取XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不需要阅读复杂的XML文件。我只想用最简单的XML阅读器阅读以下配置文件

I don't need to read complex XML files. I just want to read the following configuration file with a simplest XML reader

<config>
    <db-host>localhost</db-host>
    <db-port>3306</db-port>
    <db-username>root</db-username>
    <db-password>root</db-password>
    <db-name>cash</db-name>
</config>

如何通过Java使用XML阅读器阅读上述XML文件?

How to read the above XML file with a XML reader through Java?

http://i45.tinypic.com/2eamoeg.jpg

推荐答案

由于您要解析配置文件,我认为 commons-configuration 将是最佳解决方案。

Since you want to parse config files, I think commons-configuration would be the best solution.


Commons Configuration提供通用配置接口,使Java应用程序能够从各种源(包括XML)读取配置数据

Commons Configuration provides a generic configuration interface which enables a Java application to read configuration data from a variety of sources (including XML)

这篇关于如何用Java读取XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆