Parsing XML files using JDOM

Unlike text data, which is often unstructured, organizing data in XML files is a popular method to prepare, convey, and exploit data in a structured way. There are several ways to parse contents of XML files. In this book, we will limit our recipes to an external Java library for XML parsing named JDOM.

Getting ready

In order to perform this recipe, we will require the following:

  1. Download version 2.06 of the JAR file for JDOM from
  2. In Eclipse, create a project and include the JAR file an external JAR.
  3. Open up notepad. Create a new file named xmldummy with the .xml extension. The content of the file will be as simple as follows:
 <?xml version="1.0"?> <book> <author> <firstname>Alice</firstname> ...

Get Java Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.