小编典典

在Java应用程序中读取XML文件的最佳/最简单方法是什么?

java

当前,我们的Java应用程序使用制表符分隔的* .cfg文件中包含的值。我们需要更改此应用程序,以使其现在使用XML文件。

为了从此文件中读取值,使用的最佳/最简单的库是什么?


阅读 164

收藏
2020-09-08

共1个答案

小编典典

当然,根据您的需要有很多好的解决方案。如果只是配置,则应查看Jakarta commons-
configuration
commons-
digester

您总是可以使用获取文档的标准JDK方法:

import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

[...]

File file = new File("some/path");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(file);
2020-09-08