Is it a good idea to use JAXB to generate XML? Why or why not?
-
I often see situations where JAXB is not flexible enough. For example, we may want to generate XML dynamically. Some fields contain the data that need to be passed around. But when we return the data to users, we may want to hide the fields determined by request parameters. Since I always see exceptions when using JAXB. I start to wonder if it is a good idea to use JAXB.
-
Answer:
It is pretty straightforward to modify the output created by the JAXB Marshaller by using one of the versions of the marshal method that outputs to a SAX2 ContentHandler or a JAXP Result instance (which could be backed by DOM, SAX, StAX, or stream-based implementation). If you use one of the stream-based output methods, then you're stuck with whatever JAXB gives you, but not if you use one of the other methods. Whether or not it's a good idea for you to use JAXB in light of the former depends on whether you have any other objections to it. Your basic choice is between an annotation-based framework like JAXB or one based on external code or configuration (e.g. XStream). If you want to use annotations on your objects to drive XML output, then JAXB 2.1 has the benefit that it is bundled with Sun/Oracle's Java 6 JDK. This has the negative aspect of making it a nightmare to use a newer version of JAXB (it involves using the endorsed library path mechanism).
Mike Dillon at Quora Visit the source
Other answers
I like JAXB too, but almost always after considering it for a while during the prototyping phase, I end up using XStream because the flexibility it provides. I end up encountering some situation which requires me to go to all these forums trying to figure out how to do something in JAXB. e.g. how to write a comment.
Jon Blanton
Related Q & A:
- Is It A Bad Idea To Use Port Forwarding As A Long-term Access Strategy?Best solution by Information Security
- Is it a good idea to extract two million barrels of kerogen a day from the Green River Formation in Colorado?Best solution by Yahoo! Answers
- Is it a good idea to buy a house with your partner before you get married?Best solution by Yahoo! Answers
- Is this a good idea for a non-profit organization?Best solution by Yahoo! Answers
- Would a "with business" degree be a good idea?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.