Java XML – JDOM2 – Packages

In this tutorial we explore the package structure and important classes for Jdom2.


This package contains the core classes that represent the XML components.

  • Document – Represents the complete XML document. It provides access to the root element and also the docType.
  • DocType – Represents an XML DOCTYPE.
  • Element – Represents an XML element. Has methods to manipulate the child elements, its textual content, attributes and namespaces.
  • Attribute – This represents an XML attribute. There are methods to get and set the value of the attribute and also the namespace. The Attribute has a parent and an AttributeType.
  • Namespace – Represents an XML Namespace.
  • CDATA – This represents an XML CDATA section.
  • Text – This represents an XML Text.
  • Comment – Represents an XML comment. Users can get and set comment text.
  • EntityRef – Represents an XML EnityRef.
  • ProcessingInstruction – Represents an XML Processing Instruction
  • Content – This is an abstract class which is extended by those classes that can be a child of a org.jdom2.Parent class (Element, CDATA, Comment, DocType, EntityRef, ProcessingInstruction, Text)


These package has filters that allow filtering based on type, name, value or other parameters. It also allows ANDing, ORing and Negating filters. Filters are used in the public &ltE extends Content&gt List&ltE&gt getContent(final Filter&ltE&gt filter) and public &ltF extends Content&gt IteratorIterable&ltF&gt getDescendants(final Filter&ltF&gt filter) methods of the Element class. Filters are also using in the XPath package of JDom2.


This package has the core classes responsible for building the JDOM2 document from DOM, SAX or StAX. The important classes are

  • SAXBuilder – Builds a JDOM document from SAX parser.
  • DOMBuilder – Builds a JDOM document from pre-existing org.w3c.dom.DOM document.
  • StaxEventBuilder – Builds a JDOM document from StAX XMLEventReader
  • StaxStreamBuilder – Builds a JDOM document from StAX XMLStreamReader


These package has classes to ouput the JDOM2 document to various destinations. The main classes are :

  • XMLOutputter – Output a JDOM2 document as a stream of bytes.
  • DOMOutputter – Convert a JDOM2 document into a DOM document. It can also convert various JDOM2 components to its equivalent DOM components
  • SAXOutputter – Convert a JDOM2 document into a stream of SAX events
  • StAXEventOutputter – output a JDOM2 document to an XMLEventWriter.
  • StAXStreamOutputter – Output a JDOM2 document to an XMLStreamWriter.

Other Packages

  • org.jdom2.transform – Helps with XML transformation using JAXP TrAX classes.
  • org.jdom2.xpath – Support for XPath in JDOM2. By default, it uses the Jaxen xpath library

Leave a Comment