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.
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.
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.
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.