There are of course a lot of good solutions based on what you need. If it is just configuration, you should have a look at Jakarta commons-configuration and commons-digester.

You could always use 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);
Answer from Guillaume on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java_xml โ€บ index.htm
Java XML Tutorial
XML (EXtensible Markup Language) ... means to transport and store data. JAVA provides excellent support and a rich set of libraries to parse, modify or inquire XML documents....
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ series โ€บ a guide to xml in java
A Guide to XML in Java | Baeldung
September 28, 2023 - A SAX parser is an event-based ... Parser is median between DOM and SAX parser. ... JAXB โ€“ Java Architecture for XML Binding โ€“ is used to convert objects from/to XML....
Discussions

Why is Java so addicted to XML?
XML provides type safety and validation. It also provides a pretty rich meta data structure (attributes associated with values). Arguably these are pretty useful features. In the EJB 1.0 spec, people used code to configure a lot of the details about who could access what and how all the parts tied together. These were mostly deployment centric data points. In the EJB 2.0 spec, XML was introduced to make so non-coders could do the deployment centric configuration either through external tools or the files themselves. Spring was introduced and brought in some best practices related to other patterns and maintained this style of configuration. Then Java switched to annotations and brought it back into code with the option to override via XML Spring was also updated to support this behavior, and if I'm not mistaken, were big proponents. a lot of other dynamic languages surfaced that learned from this complexity and introduced convention based linking and configuration. Spring and Java have been updated to support this either dynamically or through code generation which is supposed to provide work-arounds to the lock-in you get from a lot of the dynamic platforms. More on reddit.com
๐ŸŒ r/java
92
48
April 9, 2014
What are some well maintained XML libraries?
JAXB. Jackson. If support for either of those is dropped then a large percentage of systems are screwed. More on reddit.com
๐ŸŒ r/java
25
25
April 8, 2024
Top answer
1 of 10
58

There are of course a lot of good solutions based on what you need. If it is just configuration, you should have a look at Jakarta commons-configuration and commons-digester.

You could always use 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);
2 of 10
40

XML Code:

<?xml version="1.0"?>
<company>
    <staff id="1001">
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </staff>
    <staff id="2001">
        <firstname>low</firstname>
        <lastname>yin fong</lastname>
        <nickname>fong fong</nickname>
        <salary>200000</salary>
    </staff>
</company>

Java Code:

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

public class ReadXMLFile {

  public static void main(String argv[]) {
    try {
    File fXmlFile = new File("/Users/mkyong/staff.xml");
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(fXmlFile);
    doc.getDocumentElement().normalize();

    System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
    NodeList nList = doc.getElementsByTagName("staff");
    System.out.println("----------------------------");

    for (int temp = 0; temp < nList.getLength(); temp++) {
        Node nNode = nList.item(temp);
        System.out.println("\nCurrent Element :" + nNode.getNodeName());
        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
            Element eElement = (Element) nNode;
            System.out.println("Staff id : "
                               + eElement.getAttribute("id"));
            System.out.println("First Name : "
                               + eElement.getElementsByTagName("firstname")
                                 .item(0).getTextContent());
            System.out.println("Last Name : "
                               + eElement.getElementsByTagName("lastname")
                                 .item(0).getTextContent());
            System.out.println("Nick Name : "
                               + eElement.getElementsByTagName("nickname")
                                 .item(0).getTextContent());
            System.out.println("Salary : "
                               + eElement.getElementsByTagName("salary")
                                 .item(0).getTextContent());
        }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
  }
}

Output:

----------------

Root element :company
----------------------------

Current Element :staff
Staff id : 1001
First Name : yong
Last Name : mook kim
Nick Name : mkyong
Salary : 100000

Current Element :staff
Staff id : 2001
First Name : low
Last Name : yin fong
Nick Name : fong fong
Salary : 200000

I recommended you reading this: Normalization in DOM parsing with java - how does it work?

Example source.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-xml-parsers-1
Java XML Parsers - GeeksforGeeks
June 27, 2024 - XML is a versatile data format that is to be used for storing and transporting structured information. A significant amount of configuration files, data interchange, and others are done using XML in Java.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ read-and-write-xml-files-in-java
How to Read and Write XML Files in Java? - GeeksforGeeks
July 27, 2025 - XML is defined as the Extensible Markup Language, and it is mostly used as a format for storing and exchanging data between systems. To read and write XML files, Java programming offers several easily implementable libraries.
๐ŸŒ
Reddit
reddit.com โ€บ r/java โ€บ why is java so addicted to xml?
r/java on Reddit: Why is Java so addicted to XML?
April 9, 2014 -

My primary job is working on Java applications for a large business. It is what you would call "the enterprise". I deal a lot with such fun things as Java EE, Tomcat/JBoss/WebSphere and Spring on a daily basis. Nearly everything I do on my day to day has me diving into XML. My maven build scripts are thousands of lines of xml (Ant wasn't much better either). My server configuration files are XML. Heck, my application, if youre using Spring, is probably a bunch of XML files with some handwritten Java scattered about. Even worse when you get into the kitchen sink aspects of spring where literally your'e application's execution flow is XML (Spring Integration, Spring Batch, and Camel routes). I feel like I'm not even a Java programmer anymore

My question is two fold:

  1. How and why is Java so addicted to XML?

  2. Is there any communities or open source projects that are presenting alternatives? The Groovy and Scala communities seem to have largely abandoned heavy XML configurations and favored DSL's or as expressing configuration as just code.

PS: On the Maven thing I know their is Gradle as an alternative, but it doesn't have the mindshare where a risk averse enterprise will train employees on "new" tools when their developers have already been using a functioning one for years

Find elsewhere
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ java โ€บ javase โ€บ 11 โ€บ docs โ€บ api โ€บ java.xml โ€บ module-summary.html
java.xml (Java SE 11 & JDK 11 )
January 20, 2026 - Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX), the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API. ... In addition to the standard features and properties described within the public APIs of this module, the JDK implementation supports ...
๐ŸŒ
W3Schools
w3schools.com โ€บ xml โ€บ xml_whatis.asp
XML Introduction
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
๐ŸŒ
Inductive Automation
docs.inductiveautomation.com โ€บ ignition platform โ€บ scripting โ€บ scripting examples โ€บ parsing xml with java libraries
Parsing XML with Java Libraries | Ignition User Manual
This data can be accessed using the Element object's built-in functionality. Using the functions above, let's parse through a sample XML string and extract employee data. We'll demonstrate how to access different elements and attributes and display them. Let's iterate through the XML elements and print out the following employee details: ... Employee ID: 1 Name: John Doe Department: Engineering Employee ID: 2 Name: Jane Smith Department: Marketing ... from javax.xml.parsers import DocumentBuilderFactory from java.io import ByteArrayInputStream # Define your XML string xmlString = """ <employee
๐ŸŒ
Vogella
vogella.com โ€บ tutorials โ€บ JavaXML โ€บ article.html
Java and XML - Tutorial
Java and XML. This article gives an introduction into XML and its usage with Java.
๐ŸŒ
Mkyong
mkyong.com โ€บ home โ€บ java โ€บ how to write xml file in java โ€“ (dom parser)
How to write XML file in Java โ€“ (DOM Parser) - Mkyong.com
May 12, 2021 - TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); // pretty print XML transformer.setOutputProperty(OutputKeys.INDENT, "yes"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(output); transformer.transform(source, result); ... The below example uses a DOM parser to create and write XML to an OutputStream. ... package com.mkyong.xml.dom; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; import javax.xml.parsers.D
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ how to use xml files (in java)?
r/learnprogramming on Reddit: How to use XML files (In Java)?
March 2, 2014 -

So I was poking through the files of a few games, namely FTL, and I noticed they had a lot of their data organized into XML files.

Now I understand that XML files are for organizing data, I just don't understand how this data gets pulled from those files into a program to be used.

What do people use to get the data from the files, and implement it into code, namely in Java, as that's the language I am currently most familiar with.

Edit: Also, is it common to use XML files? Is there something better that's come out?

๐ŸŒ
Semgrep
semgrep.dev โ€บ blog โ€บ 2023 โ€บ xml-security-in-java
XML Security in Java | Semgrep
January 17, 2023 - Vasilii and I created attack payloads for each of the 10 ways to include external content into XML documents. We tested 10 classes and there are 16 security features to test, resulting in 160 parser configurations. To test these configurations, we tried to parse each of the 10 payloads and verified whether or not external requests were made. Thus, we ran 1600 tests! The full table of results can be found in our ยท Java XXE Cheatsheet.
๐ŸŒ
George Washington University
www2.seas.gwu.edu โ€บ ~simhaweb โ€บ java โ€บ xml โ€บ xml.html
XML and Java Tutorial
An XML parser in Java allows a Java programmer to include a parser package and write applications to extract data from XML files.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ xml โ€บ xml libraries support in java
XML Libraries Support in Java
June 20, 2025 - Itโ€™s very simple to load, create and manipulate information from an XML file using JAXB. We just need to create the correct java entities to bind the XML and thatโ€™s it.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ reading-and-writing-xml-in-java
Reading and Writing XML in Java
July 26, 2023 - Another difference is that each ... and write it as any other text file. Java, however, provides a convenient way of manipulating XML using the framework called Java Architecture for XML Binding, or JAXB for short....
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ java developer โ€บ xml in java
XML in Java
March 6, 2023 - In Java development, this format ... So, let's start with the easy stuff: the "what" and the "why"! XML stands for eXtensible Markup Language....
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-XML-file-in-Java
How to create an XML file in Java - Quora
Answer (1 of 2): I am not a professional programmer but I use Java and XML for my personal projects. I have written a class I called Markup that I use to generate valid XML and HTML. It uses the ArrayDeque class to help ensure elements are nested correctly (using push and pop). I expect a profess...