How to read an XML file with Java?

I like jdom:

SAXBuilder parser = new SAXBuilder();
Document docConfig = parser.build("config.xml");
Element elConfig = docConfig.getRootElement();
String host = elConfig.getChildText("host");

You could use a simple DOM parser to read the xml representation.

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();
dom = db.parse("config.xml");

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

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

Tags:

Java

Xml