More Than an API

More Than an API

Before you get too far into working with JAXP, you need to understand a little bit about exactly what JAXP is. Sun calls it the Java API for XML Processing, although it might better be known as the Java Abstraction Layer for XML Processing. JAXP doesn't provide any original functionality, but instead sits on top of existing APIsmost notably SAX and DOM, which of course you're already familiar with, as well as TrAX and a few other APIs which you'll learn about in this chapter.

XML Parsing and Validation

For parsing XML, JAXP allows you to make method calls that affect either SAX parsing or DOM processing. As you'll see shortly, you can either work with SAX and DOM through the JAXP layer, or use JAXP to obtain a SAX or DOM parser and then interact directly with those APIs.

For those of you who think you'll never use SAX or DOM, this should help you change your mind. Anyone who uses JAXP is going to need to have at least passing familiarity with SAX and DOM, and if you want to get the most out of JAXP, you better know these underlying APIs inside and out. JAXP doesn't replace SAX or DOM; it simply supplements them.

In addition to providing a Sun-endorsed means of operating upon XML, recent versions of Sun's JDK and JRE come bundled with JAXP. For example, Java 5.0 includes JAXP 1.3 (the very latest and greatest) alongside other standard Java APIs like Swing, AWT, and Collection classes. Even more important, the servers and systems you deploy on will all have JAXP support as long as they have a recent version of Java running on them. This guarantee makes it a lot simpler to write XML applications, and know they'll run normally on various servers.

In the same vein, JAXP provides a full-featured validation API. Unlike SAX and DOM, though, JAXP breaks out most of its validation functionality into a separate package and set of classes. With this separation comes a lot more flexibility, allowing you to work with DTDs, XML Schema, or even Relax NG schemas, all while staying within the JAXP framework.

XSL Processing

JAXP provides for XML transformations in addition to parsing and validation. You can process XSL stylesheets, apply them to XML documents, and even re-process and validate the output. While you're already familiar with the APIs that underlie JAXP's parsing, the XML transformations API will be new to many of you. Called TrAXthe Transformations API for XMLyou can handle all the transformation tasks you'll probably ever run into.

It's also worth noting that TrAX is awfully simple to use. I'm not sure I could fill up even a medium-sized chapter of TrAX details if I tried, at least not without getting into details that you'll use less than two percent of the time in real-world application programming.


In recent years, XML developers and authors have fallen in love with XPath. It's easy to locate elements that match a certain name, an attribute that has a specific value, or even the third child of the second element beneath the fourth item listing in an XML document, as long as you have XPath available. XPath has been crucial to XSL since its inception, but Java APIs have recently made using XPath simple for us bytecode guys as well.

 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows