Does anyone know the solution for working with XML in Java that meets these requirements?
- Ability to fluently define XML schema (with no XSD)
- Ability to work with XML data via Java standard types: if I say that this attribute of this tag is an integer, I’d like to be able to read and write it as
int, without parsing and converting it to string manually.
The ideal solution is like this:
class MyXmlData {
@Bind("...xpath here...", Bind.Required)
public Integer numberOfPersons; // required, integer
@Bind("...xpath here...")
public String title; // optional
}
try { // throws, if required fields are not present
MyXmlData data = MagicXml.read(MyXmlData.class, "1.xml");
// at this point data.numberOfPersons is never null and
// title may be null
int myNumOfPersons = data.numberOfPersons; // here we go
}
Check out EclipseLink JAXB (MOXy). Our
@XmlPathannotation is similar to the@Bindannotation that you are looking for:For More Information