How To Read XML File In Java using JDOM Parser

287 Flares Twitter 0 Facebook 0 Google+ 287 LinkedIn 0 Filament.io 287 Flares ×

JDOM is a java representation of an XML document. JDOM is not related to the W3C’s DOM and is a Java based document object model for XML. The purpose of both DOM and JDOM are same but JDOM is much simpler and easier to use. JDOM is not an XML parser but a document object model that uses parser’s to construct documents.The default XML parser used by JDOM is the JAXP-selected parser, but JDOM can use nearly any parser.

The primary goals of JDOM is

  • should be straightforward for Java programmers.
  • should support easy and efficient document modification.
  • should hide the complexities of XML wherever possible, while remaining true to the XML specification.
  • should integrate with DOM and SAX.
  • should be lightweight and fast.
  • should solve 80% (or more) of Java/XML problems with 20% (or less) of the effort

JDOM is not bundled with JDK like a JAXB. To try out JDOM you need to download the JDOM jars and put in the project classpath. You can download the JDOM from http://www.jdom.org/downloads/source.html

XML File

Java Source File

Output