Reading XML Documents with JDOM

Naturally, JDOM can read existing XML documents from files, network sockets, strings, or anything else you can hook a stream or reader to. JDOM does not, however, include its own native parser. Instead it relies on any of a number of very fast, well-tested SAX2 parsers such as Xerces and Crimson.

The rough outline for working with an existing XML document using JDOM is as follows:

  1. Construct an org.jdom.input.SAXBuilder object using a simple no-args constructor.

  2. Invoke the builder's build() method to build a Document object from a Reader, InputStream, URL, File, or String containing a system ID.

  3. If there's a problem reading the document, an IOException is thrown. If there's a problem building the document, a JDOMException ...

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.