XML in Java Really Really Sucks

For years now, people who know me have had to endure my endless rants about the pain that one must go through to do XML processing in Java. It brings back memories of my younger years of watching the Simpsons. There was an episode where Lisa Simpson was performing a science experiment on Bart by hooking up charged electrodes to a cupcake and predicting when Bart will learn that the cupcake is hazardous. Needless to say, Bart was the victim of a very cruel joke.

In many ways, I classify the poor sucker… err… I mean Java developer who must process and deal with XML a victim of a very cruel joke. First, there was the whole SAX and JAXP fiasco of API declarations vs actual implementations. For a while, it seemed that each major project/utility would include its own XML parser implementations and they would all be on different versions. Talk about write once, class cast exception everywhere.

Admittedly, those Java tools have gotten much better over the years. But dealing with XML in Java still amounts to an over abundance of classes, endless getters and setters, and in some cases, code generation and maintenance overhead. In having worked with specifications such as Dublin Core and IMS, I know for a fact that I prefer having my dentist drill into my mouth with sharp instruments over XML processing in Java. At least, the pain caused by my dentist will eventually go away.

What if, we think outside the Java box? Dynamic languages like Javascript can make a huge difference in how we view XML. We run our XML document through a schema validator. At this point, we know our document is acceptable. There is no need to enforce type safety and be troubled by all those different classes. Why not build our document tree starting from a simple object.

What if, we integrate Rhino and use Javascript and ECMAScript for XML (E4X) for XML processing in a Java project? Hey, while we’re at it, why not integrate Javascript into server side html templating?

Oh, I can only dream…

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply