JDOM is an open source Java-based document object model for XML that was designed specifically for the Java platform so that it can take advantage of its language features. JDOM integrates with Document Object Model (DOM) and Simple API for XML (SAX), supports XPath and XSLT. It uses external parsers to build documents. JDOM was developed by Jason Hunter and Brett McLaughlin starting in March 2000. It has been part of the Java Community Process as JSR 102, though that effort has since been abandoned.
Suppose the file "foo.xml" contains this XML document:
One can parse the XML file into a tree of Java objects with JDOM, like so:
In case you don't want to create the document object from any file or any input stream, you can create the document object against the element.
As a converse, one can construct a tree of elements, then generate an XML file from it, as in the following example:
- Je t'aime je t'aime
Oh oui je t'aime
- Moi non plus
- Oh mon amour
- Comme la vague irrésolue
Je vais, je vais et je viens
Entre tes reins
Je vais et je viens
Entre tes reins
Et je me retiens
- Je t'aime je t'aime
Oh oui je t'aime
- Moi non plus
- Oh mon amour
Tu es la vague, moi l'île nue
Tu vas, tu vas et tu viens
Entre mes reins
Tu vas et tu viens
Entre mes reins
Et je te rejoins
- Je t'aime je t'aime
Oh oui je t'aime
- Moi non plus
- Oh mon amour
- L'amour physique est sans issue
Je vais je vais et je viens
Entre tes reins
Je vais et je viens
Je me retiens
- Non ! maintenant viens...