Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

In my Java application, I use values held within a tab-delimited *.cfg file. I want to change this application to use an XML file. 

Can anyone tell me what’s the best simplest library to read in values from an XML file in a Java application? 

1 Answer

0 votes
by (19.7k points)

If you are talking only about configuration, you can take a look at Jakarta commons-configuration and commons-digester.

See the code below which uses the standard JDK method of getting a document :

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);

Interested in Java? Check out this Java Certification by Intellipaat.  
 

Browse Categories

...