Java XML – JDOM2 – SAXBuilder Example

In this tutorial we look at how to build a JDOM2 using a SAXBuilder. To understand how SAXBuilder works and how to configure it look at this tutorial. The example below demonstrates the following

  • Building a JDOM2 document using a SAXBuilder.
  • Obtaining the DOCTYPE of the document.
  • Obtaining the root element of the document
  • Obtaining a specific child (specify name) of an element
  • Iterating through the descendants of an Element and printing the values of all elements whose type is not Text or Comment
  • Iterating through the descendants of an Element and printing the elements of type Comment (using a Comment filter)

The example below uses the tomcat web.xml file which can be downloaded from
here

Leave a Reply

Your email address will not be published. Required fields are marked *