JDOM, The Java DOM (2/4) - exploring XML
JDOM, The Java DOM
DOM and JDOM head-to-headJDOM presents an XML tree as Elements and Attributes, the more generic Node interface is factored out in common base classes. NodeMaps are implemented as
java.util.HashTable, and NodeIterator is replaced with
java.util.Iterator. An inheritance tree of exceptions replaces the generic DOMException:
|DOM Interface||JDOM Class|
|DOMException||JDOMException, IllegalAddException, IllegalDataException, IllegalNameException., IllegalTargetException|
JDOM is grouped in four packages:
- the classes that represent an XML document and its parts: Attribute, Comment, DocType, Document, Element, Entity, ProcessingInstruction, plus Verifier and assorted exceptions.
- classes for reading a document into memory: DOMBuilder, SAXBuilder
- classes for writing a document onto a stream or other target (e.g. SAX or DOM application): XMLOutputter, SAXOutputter, DOMOutputter
- classes for hooking up DOM implementations:
AbstractDOMAdapter, OracleV1DOMAdapter, OracleV2DOMAdapter,
ProjectXDOMAdapter, XercesDOMAdapter, XercesDOMAdapter
Reading and Writing XML Documents with JDOM
JDOM is for both input and output, new documents can be read from a stream or constructed in memory. An
org.jdom.output.XMLOutputtersends a document from memory to an OutputStream or Writer. A JDOM document can also be sent to a SAX ContentHandler or DOM
org.w3c.dom.Documentfor further processing with a different API. JDOM can connect to any parser that supports SAX or DOM compatible parser including:
Another major effort in the Java-specific XML space is the JSR-000031 XML Data Binding Specification from Bluestone, Sun, WebMethods et al. The proposed specification will define an XML data-binding facility for the JavaTM Platform. Such a facility compiles an XML schema into one or more Java classes. These automatically-generated classes handle the translation between XML documents that follow the schema and interrelated instances of the derived classes. They also ensure that the constraints expressed in the schema are maintained as instances of the classes are manipulated.
Comparing the SAX, DOM and JDOM ways...
Created: Dec 03, 2000
Revised: Dec 03, 2000