The J2XB project aims at offering seamless Java and XML integration defined in Java. It offers the developer a tool to bind XML documents to Java types. What is special with J2XB is that no code Java generation is involved. J2XB transform the development of Java and XML binding from Java code generation to XML Schema generation.
The J2XB project is unique in that it aims at:
Binding Java classes to XML with J2XB is as simple as it can be - just annotate your classes with a few annotations and you are ready (to get the full benefit of J2XB you will need to add only annotations).
@MOPersistentBean(xmlName = "HelloWorld")
public class HelloWorld {
private String name;
private String type;
private int classID;
@MOProperty()
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@MOProperty()
public int getClassID() {
return classID;
}
public void setClassID(int classID) {
this.classID = classID;
}
@MOProperty()
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
MoXmlBindingModel xmlBindingModel = new MoXmlBindingModel(); xmlBindingModel.addBean(HelloWorld.class); xmlBindingModel.addBean(MyClass2.class);
xmlBindingModel.generateSchemas(new File("some folder"));
// using the Axiom persister XmlPersister xmlPersister = new XmlAxiomPersister();
or the XmlBeans persister (which requires to pre-compile the generated schemas (in step [[4]] above) and including the generated classes in the classpath.
// using the XmlBeans persister XmlPersister xmlPersister = new XmlBeansPersister();
HelloWorld myInstance = new HelloWorld(); xmlPersister.save(xmlBindingModel, myInstance, "c:/temp/myFile.xml");
HelloWorld myInstance = xmlPersister.load(xmlBindingModel, HelloWorld.class, "c:/temp/myFile.xml");
Have a look at the documentation to utilize the full power of J2XB, Have a look at the examples, And try J2XB!
The J2XB project is at a mature stage and offers important benefits with the feature set it includes. However, like any software project, there is still a lot that can be done to improve this project. Some of the ideas that can be added to this project are: