🌐
W3Schools
w3schools.com β€Ί xml
XML Tutorial
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.
Learn CSS
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.
Learn HTML
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.
Spaces
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.
Reference
HTML Certificate CSS Certificate JavaScript Certificate Front End Certificate SQL Certificate Python Certificate PHP Certificate jQuery Certificate Java Certificate C++ Certificate C# Certificate XML Certificate ... W3Schools is optimized for learning and training.
🌐
W3Schools Blog
w3schools.blog β€Ί home β€Ί xml parser tutorial
XML Parser Tutorial - w3schools.blog
June 29, 2015 - XML Parser tutorial java for beginners and professionals with examples in eclipse on Basics, JAVA XML Parsers, DOM Parser, Parse XML Document, Query XML Document, Create XML Document, Modify XML Document,SAX Parser, StAX Parser and more.
🌐
W3Schools
w3schools.com β€Ί xml β€Ί xml_whatis.asp
Introduction to XML
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.
🌐
W3Schools
w3schools.com β€Ί js β€Ί js_ajax_applications.asp
XML Applications
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.
🌐
W3Schools
w3schools.com β€Ί java
Java Tutorial
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.
🌐
George Washington University
www2.seas.gwu.edu β€Ί ~simhaweb β€Ί java β€Ί xml β€Ί xml.html
Getting Started with XML and Java
The W3C DOM (Document Object Model) API. This set of Java classes implements the "tree-based" parser. There are methods for traversing a tree and extracting/inserting information. We will parse the file student.xml using IBM's XML parser.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί java β€Ί java-xml-parsers-1
Java XML Parsers - GeeksforGeeks
June 27, 2024 - In-Memory Operations: Ideal for applications that require taking the entire XML structure into memory and manipulating it. Pros: Can be easily used and has robust navigation and modification abilities. Cons: Memory intensive, inefficient for large documents. ... 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; public class DomParserExample { public static void main(String[] args) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuild
🌐
W3Schools
w3schools.com β€Ί xml β€Ί dom_intro.asp
XML DOM Tutorial
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.
Find elsewhere
🌐
Mkyong
mkyong.com β€Ί home β€Ί java β€Ί how to read xml file in java – (dom parser)
How to read XML file in Java - (DOM Parser) - Mkyong.com
April 1, 2021 - package com.mkyong.xml.dom; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.io.InputStream; public class ReadXmlDomParser { private static final String FILENAME = "/users/mkyong/staff.xml"; public static void main(String[] args) { // Instantiate the Factory DocumentBuilderFactory dbf = DocumentBu
🌐
TutorialsPoint
tutorialspoint.com β€Ί java_xml β€Ί index.htm
Java XML Tutorial
Yet, it is not a big issue if you don't know anything about XML because we have a chapter named "Java XML overview" that covers all the basics of XML that are required for this tutorial. There are some very Frequently Asked Questions(FAQ) about Java XML, this section tries to answer them briefly.
🌐
W3Schools
w3schools.invisionzone.com β€Ί xml forums β€Ί xml
Jaxp Xml Processing - XML - W3Schools Forum
April 19, 2009 - I need to do some simple XML processing using Java. All I have to do is step through an XML file until I find a match to a file name that is stored within each element. I use Java often, but I'm unfamiliar with the JAXP APIs. Can anyone get me started?
🌐
W3Schools
w3schools.com β€Ί whatis β€Ί whatis_xml.asp
What is XML
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.
🌐
W3schoolsapp
w3schools.w3schoolsapp.com β€Ί java β€Ί default.html
Java Tutorial
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.
🌐
W3Schools
w3schools.com β€Ί XML β€Ί xml_dom.asp
XML DOM
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.
🌐
W3Schools
w3schools.com β€Ί xml β€Ί xml_elements.asp
XML Elements
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.
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.

🌐
W3Schools
w3schools.com β€Ί java β€Ί java_examples.asp
Java Examples
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.
🌐
W3Schools
w3schools.com β€Ί java β€Ί java_intro.asp
Introduction to Java
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.
🌐
W3Schools
w3schools.com β€Ί xml β€Ί xml_parser.asp
XML Parser
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.