Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
What I need is a summer intern: someone who can get me lunch and do my dirty work for me -- like writing Java classes that correspond to every XML document type I work with. These Java classes could turn XML documents into my program's objects. Each XML tag would map to an object attribute, and a tag's contents would be the attribute value. Then, for a real challenge, I'd ask my intern to provide a marshal method in each Java class.
"Who's Marshal?" the intern might ask.
"A military officer who marshals things, arranges things in methodical order," I'd explain smugly.
Marshaling a Java object means converting it to XML format for storage or for sending. It's like when you fold your socks to put them neatly away -- which, come to think of it, is something else my intern could do. Later, when you or someone else wears those socks again, it's like turning an XML document back into useable Java objects -- unmarshaling. And you'll agree that, when you wake up in the morning, it's nice to find a basket full of neatly folded socks.
This is the classic marshal and unmarshal diagram, but for fun, this one illustrates my socks analogy.

Marshaling and unmarshaling
The ability to work with unmarshaled XML documents would be great because I could use and maintain regular Java objects much more easily and naturally than I could with a bunch of XML parsing code. My unmarshaled Java objects could even validate attributes based on the original XML Schema constraints. This validation would include type checking and verifying range values. I would have a way to programmatically construct a Java object that could save itself as an XML document valid against a certain XML Schema. Now we're talking! But what about performance? Using these unmarshaled objects, my application would be faster than SAX parsing and require less memory than DOM parsing.
Do you want to work as my intern this summer? I know what you're thinking: writing the marshal, unmarshal, and validating-accessor methods based on schema constraints would be a long and tedious task. In addition, every time I changed my XML Schema, you'd have to update this code. Doing my laundry wouldn't be much fun either. Doesn't matter; I don't want to baby-sit and entertain an intern all summer anyway. I've got better things to do!
What if I told you that there already are XML data-binding frameworks that can generate this type of marshaling and unmarshaling code for you? Just feed in a DTD (document type definition) or an XML Schema and -- presto! -- you have Java classes that can marshal, unmarshal, and check data constraints. And like many Java XML tools, these frameworks are mostly free. In this article, we'll examine two such frameworks: Sun's Java Architecture for XML Binding (JAXB) and Castor from the Exolab Group.