JDOM models an XML document as a Document object which contains a List of Comment and ProcessingInstruction objects and a single Element object for the root element.

Each Element object contains a List of its children: Comment, ProcessingInstruction, Text, and other Element objects. In addition, it has separate lists of attributes and additional namespaces. The list of children is accessible through the getContent() method. Content can be appended to an element or to a document with the heavily overloaded addContent() method or removed from the tree using the heavily overloaded removeContent() method. However, other mutation operations such as inserting a node at the beginning or in the middle of an element’s children require using the methods of java.util.List.

With the exception of Namespace, the JDOM core node classes have public constructors, and are constructed in about the most obvious ways you can imagine. For instance, to create a new Attribute object that represents the attribute revision="20020430", you’d use the constructor Attribute("revision", "20020430"). Namespaces and local names are always separated in argument lists. Sometimes namespaces are provided as one or two strings containing the namespace URI and the optional prefix. Other times they’re provided as a combined Namespace object. (JDOM’s not perfectly consistent here.)

All the core node classes have the getter and setter methods you’d expect; e.g. setTarget(), getTarget(), setData(), and getData() for ProcessingInstruction; setName(), getName(), setNamespace(), and getNamespace() for Element and so forth. In addition they’re a few common methods that show up across several classes. The detach() method removes a node from its parent. The getParent() method returns a node’s parent element. And all the JDOM nodes provide the usual Java utility methods equals(), hashCode(), and toString(). Finally, all these classes implement both Serializable and Cloneable and; all override clone().

Copyright 2001, 2002 Elliotte Rusty Haroldelharo@metalab.unc.eduLast Modified May 03, 2002
Up To Cafe con Leche