Java – Object XML Mapping

Have you written 1000s of buggie lines of code to parse XML? Generating an XML is easy but when it comes to XML parsing/import it is hard. We have to think about many scenarios and deal with many combinations. I use to prefer XPath API for XML import because I can fetch required values as they way/order I want rather than iterating all nodes in DOM structure. XPath is better than DOM coding but is not the best solution. So I started looking for a solution similar to Hibernate for XML to Object translation.

My first look was Commons Digester to translate XML to Java Object. I gone through a few page of their document they explain how to create mapping XML to map XML tags for Java classes but it is not like Hibernate where we can give RDBMS tables definition and it will generate equivalent Java classes. So I kept my search ON found a few open source tools which can generate Java classes from XML Schema but none worked as there was no activity for long time. Finally I found JAXB API which exactly meets my expectation.

Advantages of JAXB

  • Java classes can be generated from DTD or Schema definition.
  • Marshall (XML export) and Unmarshall (XML import) are part of JRE hence no additional jars required.
  • Easy/Simple to use API.
  • You can enjoy writing more Java code (i.e. business logic) and no parsing code.

Reference:
http://java.sun.com/developer/technicalArticles/WebServices/jaxb/

Added Nov 17, 2009

http://www.javarants.com/2006/04/30/simple-and-efficient-xml-parsing-using-jaxb-2-0/comment-page-1/

While writing this post I remember the below quote:
“Complexity is a sign of technical immaturity. Simplicity of use is the real sign of a well design product whether it is an ATM or a Patriot missile.”
– Daniel T. Ling

Advertisements

4 Responses to Java – Object XML Mapping

  1. Nice heads up, Venkat…

  2. Vikram Bailur says:

    JAXME is an implementation of JAXB – http://ws.apache.org/jaxme/

  3. Venkat says:

    Thanks Vikram.

  4. site88.net says:

    This is my first time pay a quick visit at here and
    i am in fact happy to read everthing at single
    place.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: