O'Reilly logo

Java and XML by Brett McLaughlin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

JDOM 1.0

JDOM 1.0, introduced in Chapter 8, provides a complete view of an XML document within a tree model. Although this model is similar to DOM, it is not as rigid a representation; this allows the content of an Element, for example, to be set directly, instead of setting the value of the child of that Element. Additionally, JDOM provides concrete classes rather than interfaces, allowing direct instantiation of objects rather than through the use of a factory. SAX and DOM are only used in JDOM for the construction of a JDOM Document object from existing XML data, and are detailed in the org.jdom.input package.

Package: org.jdom[22]

This package contains the core classes for JDOM 1.0. These consist of XML objects modeled in Java and a set of Exceptions that can be thrown when errors occur.

Attribute

Attribute defines behavior for an XML attribute, modeled in Java. Methods allow the user to obtain the value of the attribute as well as namespace information about the Attribute. An instance can be created with the name of the attribute and its value, or the Namespace and local name, as well as the value, of the attribute. Several convenience methods are also provided for automatic data conversion of the attribute’s value.

public class Attribute { public Attribute(String name, String value); public Attribute(String name, String prefix, String uri, String value); public Attribute(String name, Namespace ns, String value); public String getName( ); public String getQualifiedName( ); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required