Castor is an Open Source data binding framework for Java[tm].Castor provides Java-to-XML binding
Castor XML can marshal almost any "bean-like" Java Object to and from XML. In most cases the marshalling
framework uses a set of ClassDescriptors and FieldDescriptors to describe how an Object should be marshalled
and unmarshalled from XML.
The mapping rules can be mentioned in xml files which makes it easy for customization.
It also has features for java code generation from xml.
http://www.castor.org/
Saturday, May 16, 2009
Caster - XML/JAVA Object Mapping
JAXB -Xml/Java Mapping
After looking at many options which helped me convert java classes into xml and vice versa, i found this JAXB very exciting.The Java Architecture
for XML Binding provides a powerful and practical way of working with XML content from within Java applications. The newly released JAXB 2.0 offers
many new features, including full support of all XML Schema features, significantly fewer generated classes, generated classes that are easier to
manipulate, and a more flexible validation mechanism.
JAXB prerequisites
To get started with JAXB 2.0 you need:
1 Java Platform, Standard Edition 5: JAXB 2.0 relies heavily on features of Java SE 5, such as annotations and generics
2. An implementation of JAXB 2.0
I chose this implementation - https://jaxb.dev.java.net/
To start with the JAXb we first need to generate java classes using the xsd.This can be easily done ussing the xjc compiler
syntax : $xjc
Once this command are exceuted the classes are generated in teh given package.These can be used to marshel and unmarshel the xml quite easily.
First we create a JAXBContext
JAXBContext jaxbContext = JAXBContext.newInstance("package.of.the.generated.classes");
Then carete a unmarsheller using the context
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Use the unmarshellor to get the data objects for the xml
DataObj data = (DataObj) unmarshaller.unmarshal(url);
url is URL which returns the xml response.Also xml can be given from a file directly
this data object can ve used to access all other valuse presnt in the xml response.
Ref : http://java.sun.com/developer/technicalArticles/WebServices/jaxb/
http://www.javaworld.com/javaworld/jw-06-2006/jw-0626-jaxb.html
Wednesday, November 12, 2008
XStream - Convert XMl to Java & Vice Versa
</person></code>