Java – How to generate simple-xml java annotated object from xsd schema

androidjavasimple-frameworkxmlxsd

Ok, so I've searched stackoverflow and found unanswered sub-topics regarding this issue, that's why I'd like to have this question clearly pointed out:

Is there any tool that will generate the Simple Xml library's annotated java class from an xsd schema?

I received a couple of xsd files describing the objects returned by a restful web-service someone else has developed and currently I've translated those schemas to the simple-xml annotated classes. Those will be used in my Android app. It would be better to just automatically synchronize any changes to the schemas and regenerate the classes from them. The ws guys have a repository of Jackson compliant classes for those schemas, however I don't want to use Jackson – I'm using Spring Android, so I'd prefer to go with the preferred simple-xml. There must be something that does the trick like JAXB's xjc tool.

If there is no such tool – can you think of any traps in implementing a script that generates a .java file for simple-xml from the schema? Maybe any hints for tools worth extending that would just require defining what annotations to generate and when?

In advance – thanks a lot for your answers!

Best Answer

I do not believe that JAXB can be used on Android because of missing package requirements (see here), especially with earlier versions of the Android API. What you could do instead is send your XSD through xjc and get JAXB class output and then write a script to convert the JAXB annotations into the equivalent Simple XML annotations. This should do exactly what you were looking for.

However, ideally, and if you had the time, you could check out the source for xjc and extend it to be able to output JAXB or Simple annotated classes.