Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Easy Java/XML integration with JDOM, Part 1

Learn about a new open source API for working with XML

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
JDOM is an open source API designed to represent an XML document and its contents to the typical Java developer in an intuitive and straightforward way. As the name indicates, JDOM is Java optimized. It behaves like Java, it uses Java collections, and it provides a low-cost entry point for using XML. JDOM users don't need to have tremendous expertise in XML to be productive and get their jobs done.

TEXTBOX: TEXTBOX_HEAD: Easy Java/XML integration with JDOM: Read the whole series!

:END_TEXTBOX

JDOM interoperates well with existing standards such as the Simple API for XML (SAX) and the Document Object Model (DOM). However, it's more than a simple abstraction above those APIs. JDOM takes the best concepts from existing APIs and creates a new set of classes and interfaces that provide, in the words of one JDOM user, "the interface I expected when I first looked at org.w3c.dom." JDOM can read from existing DOM and SAX sources, and can output to DOM- and SAX-receiving components. That ability enables JDOM to interoperate seamlessly with existing program components built against SAX or DOM.

JDOM has been made available under an Apache-style, open source license. That license is among the least restrictive software licenses available, enabling developers to use JDOM in creating products without requiring them to release their own products as open source. It is the license model used by the Apache Project, which created the Apache server. In addition to making the software free, being open source enables the API to take contributions from some of the best Java and XML minds in the industry and to adapt quickly to new standards as they evolve.

The JDOM philosophy

First and foremost, the JDOM API has been developed to be straightforward for Java programmers. While other XML APIs were created to be cross-language (supporting the same API for Java, C++, and even JavaScript), JDOM takes advantage of Java's abilities by using features such as method overloading, the Collections APIs, and (behind the scenes) reflection.

To be straightforward, the API has to represent the document in a way programmers would expect. For example, how would a Java programmer expect to get the text content of an element?

<element>This is my text content</element>


In some APIs, an element's text content is available only as a child Node of the Element. While technically correct, that design requires the following code to access an element's content:

String content = element.getFirstChild()
                    .getValue();


However, JDOM makes the text content available in a more straightforward way:

String text = element.getText();


Wherever possible, JDOM makes the programmer's job easier. The rule of thumb is that JDOM should help solve 80 percent or more of Java/XML problems with 20 percent or less of the traditional effort. That does not mean that JDOM conforms to only 80 percent of the XML specification. (In fact, we expect that JDOM will be fully compliant before the 1.0 final release.) What that rule of thumb does mean is that just because something could be added to the API doesn't mean it will. The API should remain sleek.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (6)
Login
Forgot your account info?

That does not mean that JDOMBy Aneeklive on November 7, 2009, 4:52 amThat does not mean that JDOM conforms to only 80 percent of the XML specification. (In fact, we expect that JDOM will be fully compliant before the 1.0 final release Apex...

Reply | Read entire comment

As a developer, you've probably heard of the 80-20 rule, known iBy yuridebura on September 28, 2009, 1:09 pmAs a developer, you've probably heard of the 80-20 rule, known in other circles as Pareto's Law: a process or methodology will accommodate 80 percent of all possible...

Reply | Read entire comment

ThanksBy Emma on September 4, 2009, 4:19 pmWould like to thank for the detailed explanation.

Reply | Read entire comment

javaBy Anonymous on July 21, 2009, 5:02 amI am a java programmer and eager to know more about the product yu were talking about to develop free games available here.

Reply | Read entire comment

Great IntroductionBy Pascal Landau on June 5, 2009, 11:01 amHey, I think this is a really great introduction in JDOM. I've spent hours searching a similar one in german, but I "failed" :P Regards Pascal Landau http://www.mywebsolution.de

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources