Moving to a Higher Plane
by Brett McLaughlin08/08/2001
Of course, that sounds pretty "new age, meaning of life, find yourself", so let me explain what I mean. I still remember back in the old days of XML (yes, way back in 1998), when the only choices for working with XML were writing your own code that directly read from a file or InputStream, or using SAX, the Simple API for XML. This is what I call "low-level" access, where you're basically given the keys to the kingdom, and you're welcome to blow things up as you like.
Soon after, DOM (the Document Object Model) came onto the scene. This was still certainly a lower-level API, but it presented XML in an object model that was a little more intuitive to many than SAX. Even at this point, users would often prefer DOM because it was at a slightly higher level than SAX; handling errors and building up an object tree was taken care of by the API, not the developer.
Now fast-forward about a year. JDOM emerged onto the scene, and again tried to provide convenience to developers. Like DOM, JDOM provides an object-model representation of XML. However, its main driving principle was to make things easier. Now that's obviously an oversimplification, but you get the idea.
About the same time, JAXP, Sun Microsystems' Java API for XML Processing, became available. Again, this moved things up a level by removing a developer's need to work directly with a vendor's parser implementation. JAXP was also the first API to explicitly build on top of other APIs (SAX, DOM, and in JAXP version.next, JDOM). It uses SAX and DOM for all of its processing. By the way, most DOM trees are built using SAX, but this is not required or exposed in the DOM API; JAXP provides SAX- and DOM-specific methods within its core classes. Again, developers flocked to this higher-level API, preferring it to APIs that required more developer knowledge, and demanded more care on the part of the developer.
Visit java.oreilly.com for a complete list of O'Reilly's books about Java technologies.
|
Related Reading
Java and XML |
Fast-forward again, to the present. APIs like SAX, DOM, JDOM, and JAXP are all considered low level, and you can write entire XML-based applications without ever touching any of them. The next generation of XML APIs are here, and they are truly on a "higher plane." For example, JAXB, the Java Architecture for Data Binding, allows the developer to completely bypass dealing directly with XML structure (like SAX, DOM, and JDOM require), and provides customized Java classes that have methods like getName() and setCity() for XML tags like <name> and <city>. This makes XML documents accessible even to novice developers. Another example is the SOAP API, which allows XML communication from machine to machine, without ever writing a line of XML. Again, a higher-level API uses lower-level APIs, making the developers' job easier.
So what's the point? The point is this: As we all find ourselves moving to a higher plane, we are losing the knowledge of those lower levels. Now I'm not saying that we throw out all our useful tools (like Java) and go back to assembly language. I am saying that a healthy sense of balance is in order, however.
Understanding how SAX works provides a developer with better skills in programming DOM applications; you will know how to set error handlers and resolve entities any way you want. Understanding JAXP allows debugging within JAXB, and allows you to customize the binding between XML documents and Java classes. And knowing how documents can be well formed and valid, means that you can more accurately interpret a SOAP envelope and a service response. I'm not saying throw out the higher-level APIs; I'm saying learn to use them more effectively by understanding their underpinnings.
So how do you go about that? Isn't that a pretty tall task? Well, yes it is; but I'm glad you asked anyway. The best way to handle this problem is to start at the beginning. And the beginning of all the fun in Java and XML is generally SAX.
Once you've gotten a handle on SAX, you can take a step up the API ladder and investigate DOM and JDOM, both of which use SAX for building their object structures. From there, things begin to branch out. You could choose to delve into Web services and learn about SOAP, WSDL, and UDDI. You could get into data binding, and learn how Zeus, Castor, and JAXB (all data-binding implementations) work. You might be into Web publishing and want to check out XMLC or Apache Cocoon. Or you might go in a completely different direction, and come up with something entirely new. But by starting at the beginning, down in the dirty trenches, your code will be clearer, cleaner, and well informed, even up on those high planes.
So don't be afraid of those low-level APIs. Dig in. You can start by picking up a copy of the second edition of Java & XML, which covers all these APIs, and does so in the order in which I've recommended you take them on. I hope to see your questions, and answers, on the mailing lists out there. And as always, I'll see you online.
For a look at the evolution of the first XML APIs developed for the Java platform, see Brett's Java and XML: Interested Parties Apply Here.
Brett McLaughlin is one of the leading authorities on Java, XML, enterprise applications, and open source software. He is the Enhydra strategist at Lutris Technologies, where he is responsible for the direction and strategy for the Enhydra application server. He's the founder or cofounder of numerous other open source projects, such as JDOM (currently in JSR at Sun), ApacheTurbine (a servlet-based Web applications framework), and Enhydra Zeus (an XML data-binding framework). His role as a contributor on OpenEJB, jBoss, and Apache Cocoon places him in the middle of Java and XML innovation. In addition to his technology contributions, Brett is a prolific writer; he is the author of Java & XML (O'Reilly), the moderator of IBM's Java and XML tools and technologies newsgroup, and flashline.com's biweekly component columnist. He's written dozens of articles for IBM Developer Works, JavaWorld, and oreilly.com.
O'Reilly & Associates will soon release (August 2001) Java & XML, 2nd Edition.
Sample Chapter 12, SOAP, is available free online.
You can also look at the Table of Contents, the Index, and the Full Description of the book.
For more information, or to order the book, click here.


