Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 884
chemical Avatar asked May 31 '11 20:05

chemical


People also ask

How do I generate Java classes from XSD using JAXB in Intellij?

Generate a Java class from an XML Schema using JAXB In the active editor tab, open the desired Schema . xsd file or an XML document, which contains the desired Schema. In the main menu, go to Tools | XML Actions | Generate Java Code From XML Schema Using JAXB.

How do I generate a class from XSD using JAXB?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.


1 Answers

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.

like image 164
Robert Massaioli Avatar answered Sep 25 '22 01:09

Robert Massaioli