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

2 thoughts on “Java XML – JDOM2 – SAXBuilder Example

  • January 24, 2018 at 5:11 am
    Permalink

    I can’t find the “tomcat-web-dtd.xml” from the given link

    Reply
  • March 5, 2018 at 1:07 pm
    Permalink

    This example is working one, but the xml which here described is wrong consist errors, but hura i was able to parse it with a given Java example

    Reply

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.