JDOM is an open source, tree-based, pure Java API for parsing, creating, manipulating, and serializing XML documents. Brett McLaughlin and Jason Hunter invented it in spring 2000. I asked Jason how it happened , and here is what he told me:
Since then numerous people have contributed to JDOM's development, including Alex Rosen, Alex Chaffee, James Duncan Davidson, Philip Nelson, Jools Enticknap, Bradley S. Huffman, and yours truly. JDOM is open source like SAX and DOM. (Proprietary XML APIs really have not caught on.) Hunter and McLaughlin publish it under the very liberal Apache license. Essentially you can do anything you want with it except use the name "JDOM" for derivative works. It has already been forked once, resulting in James Strachan's dom4j.
Like DOM, JDOM represents an XML document as a tree composed of elements, attributes, comments, processing instructions, text nodes, CDATA sections, and so forth. The entire tree is available at any time. Unlike SAX, JDOM can access any part of the tree at any time. Unlike DOM, all of the different kinds of nodes in the tree are represented by concrete classes rather than interfaces. Furthermore, there is no generic Node interface or class that all of the different node classes implement or extend. [1]
JDOM is written in and for Java. It consistently uses the Java coding conventions and the class library. For example, all primary JDOM classes have equals() , toString() , and hashCode() methods. They all implement the Cloneable and Serializable interfaces. The children of an Element or a Document object are stored in a java.util.List . JDOM strives to be correctnot only with respect to XML, but also with respect to Java. JDOM does not itself include a parser. Instead it depends on a SAX parser with a custom ContentHandler to parse documents and build JDOM models from them. Xerces 1.4.4 is bundled with JDOM. However, it can work equally well with any SAX2 compliant parser, including Crimson, lfred, the Oracle XML Parser for Java, Piccolo, Xerces-2, and more. Any of these can read an XML document and feed it into JDOM. JDOM can also convert DOM Document objects into JDOM Document objects, which is useful for piping the output of existing DOM programs to the input of a JDOM program. However, if you're working with a stream of XML data read from a disk or a network, it's preferable to use SAX to produce the JDOM tree, because it avoids the overhead of building the in-memory tree twice in two different representations. Like DOM (and unlike SAX), JDOM can build a new XML tree in memory. Data for the tree can come from a non-XML source such as a database, from literals in the Java program, or from calculations as in many of the Fibonacci number examples in this book. When creating new XML documents from scratch (rather than reading them from a parser), JDOM checks all of the data for well- formedness . For example, unlike many DOM implementations , JDOM does not allow programs to create comments whose data includes the double hyphen ( -- ) or elements and attributes whose namespaces conflict in impossible ways. Once a document has been loaded into memory, whether by creating it from scratch or by parsing it from a stream, JDOM can modify the document. A JDOM tree is fully read-write. All parts of the tree can be moved, deleted, and added tosubject to the usual restrictions of XML. (For example, you can add an attribute to an element but not to a comment.) Unlike DOM, there are no annoying read-only sections of the tree that you can't change. Finally, when you're finished working with a document in memory, JDOM lets you serialize it back out to disk or onto a stream as a sequence of bytes. JDOM provides numerous options to specify the encoding, indenting, line end characters , and other details of serialization. Alternately, if you don't want to convert the document to a stream, you can produce a SAX event sequence or a DOM document as output instead. ![]() |