Java Architecture for XML Binding (JAXB)
Java Architecture for XML Binding (JAXB) provides a fast and convenient way to bind XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. As part of this process, JAXB provides methods for unmarshalling (reading) XML instance documents into Java content trees, and then marshalling (writing) Java content trees back into XML instance documents. JAXB also provides a way to generate XML schema from Java objects.
In case you want to quickly develop a XML parser in Java I recommend using JAXB. It creates Java classes from xsd schemas and vice versa automatically.
Set up Eclipse for JAXB
Since I am often working in an environment where I cannot use just any software I need, it is interesting to know what needs to be done in Eclipse before you can start using JAXB.
It is pretty simple. All you need to do is installing the plugins under category "Web, XML, Java EE and OSGi Enterprise Development" available in the release repository of your current Eclipse version.
To do so select Help -> Install New Software... from the eclipse main menu bar.
- Hits: 82902
Whenever you encounter a special task in parsing XML into Java objects (un-marshaling) or Java objects into XML (marshaling) utilizing JAXB, you can get angry quite easily.
Examples are ...
- no namespace in XML, may it be marshaling or un-marshaling
- sanitized output into XML when marshaling and vice versa
- formatted output, which is easier to read
Facing these issues many times, I decided to create a special Eclipse Java project for JAXB marshaling and un-marshaling, which I can reference in other Java projects.
This is much quicker anyhow than repetitive code in different places.
- Hits: 2134
When you are working with JAXB, you have three different entry points. Either you create a whole new project, you create an xml schema from existing classes in a normal Java project or vice versa.
In this article I describe how to create a new JAXB project in Eclipse.
If you have not installed the already prepared Eclipse version for Java EE, below you can find an article on how to install the needed software into a standard Java SE Eclipse version.
In Eclipse select File -> New -> Other and type "jaxb" into the filter field of the "New" wizard.
- Hits: 9031