Creating XML Elements with JDOM

One of my favorite things about JDOM is that, 90 percent of the time, it works exactly the way I expect it to work. I don't have to look at the documentation because my best guess is almost always right. This is only sometimes true for SAX and almost never true for DOM. For example, suppose you wanted to create the JDOM representation of this element:

<fibonacci/> 

The simplest, most obvious solution I can imagine is this:

Element element = new Element("fibonacci"); 

Guess what? That's exactly how you do create an element in JDOM. Compare that with the DOM approach:

 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.