Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXP(SAX & DOM) vs JAXB

 
Sara Jahan
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this was a competition, which one you think would be the winner?

Sara
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a way, JAXB is a bundle flavoured over DOM/SAX techniques.
Logically i would choose what best fits my requirements and time.
 
Paul Clapham
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What prize would they be competing for?
 
Sara Jahan
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
What prize would they be competing for?


I would use the winner in my dev work, I guess!

The thing is I am trying to educate myself about JAXB. Most of the white papers/tutorials start with a brief intro on sax/dom where the writers have unfavourably compared them to jaxB - i.e. how simple and better JAXB is as compared to jaxP.

I was hence wondering, if that is the case then why people are still using sax/dom. I guess that I will have to find out myself after I finish with jaxB.

Sara
[ January 15, 2006: Message edited by: Sara Jahan ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would be a competition of apples and oranges. JAXB is a Java <--> XML binding mechanism, i.e. it creates Java objects from XML files and vice-versa, and is implemented on top of JAXP. SAX and DOM can be used for a variety of purposes where JAXB would be a complete mis-fit.

Of course, if it is the Java binding that you actually need, then JAXB makes that much simpler than it would be using JAXP.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Talking about which XML tech is "better" is a useless exercise since XML is used over such a huge range of applications.
 
Sudha Rams
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With reference to Ulf Dittmer's post in this thread, I've got a question:

From what I've understood, JAXB is used by Java web services implementation to convert user-defined data classes to equivalent XML representation and vice-versa, thus enabling tier-tier communication in the web services environment.

Is there anything else to JAXB apart from this? I'm just trying to appreciate the use of JAXB from the business perspective i.e. where JAXB comes into play to solve a business problem like say process data and generate a report.

For example, suppose I've got an XML (that has an XML schema) with student grades data and I need to process this data to generate a report (which again is represented in an XML format).

Using DOM API, I can traverse the nodes in this XML using XPATH, process data and generate another XML as a report.

Can I do the same for the content tree created by the JAXB unmarshaller, without marshalling that tree to a DOM node?? If no, then what is the point? Does that mean that, in this example case, DOM should suffice and usage of JAXB may not be of any value-add or will not even make sense?

Please let me know! :roll:

Also, if you can think of a business problem that JAXB is ideally suited to solve, please share it.

Thanks for your time!
[ January 17, 2006: Message edited by: Sudha Rams ]
 
Reid M. Pinchback
Ranch Hand
Posts: 775
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAXB has nothing to do with DOM. The idea of JAXB is that you can have an XML Schema definition of your types, and JAXB will create the Java object representations of those types, plus the marshalling and demarshalling helper code needed to get you from the Java world to the XML world and back.

The reason for using JAXB is that you've already decided you want to use or are willing to use XML Schema and you want a Java object representation of your XML that is closely in sync with the XML structure. The "benefit" is more from XML Schema than JAXB; you get more constraint power than you do with simple XML validation. The situation is very different from, for example, SAX, where Java representation of XML is irrelevant because SAX is only concerned with firing events when particular XML artifacts are detected during parsing.
 
Sudha Rams
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your explanation, Reid. Better late than never!
 
RayZ Wilson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel a need to reiterate what someone said above. JAXB is mainly used for web services. It allows you to work in the Java realm without having to worry about XML at all practically. The SOAP messages sent to the web service consist of an XML representation of the objects you are interacting with. You are interacting with an object model not actual XML. When the web service replies you interact with it as instances of objects as well. You never really have to do any parsing the web services interface does it all for you. JAXB gives you tools to convert WSDL to java objects which represent the web service end points.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inside JAXB and DOM implementations there is always SAX. SAX code is always at the foundation of any code using Java-based XML parsers.
 
Andrew Kid
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James, can you give some prooflinks?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JAXB is mainly used for web services.

No, it is used (and usable) in lots of places. The fact that JAX-WS uses JAXB under the hood says nothing about JAXB's potential for applications elsewhere. Java <-> XML bindings ceased to be a hot topic a couple of years ago once lots of capable frameworks for doing it become available; WS just brought it back to the front pages.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic