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 ]
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.
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 ]
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.
Reid - SCJP2 (April 2002)
Joined: May 13, 2005
Thanks for your explanation, Reid. Better late than never!
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.
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.