Jump to content
  • Advertisement
Sign in to follow this  
d000hg

[java] Auto-generate XML schema/mapping/serialization code?

This topic is 3994 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I did some SOAP web server stuff a while ago, I found libraries existed for C++ which let you create a C++ class, and it would generate WSDL schema and code to read from a received XML message into objects of the class, etc. I want to have configuration files for a Java project but writing an XML loader is about the most tedious coding task I've ever had to do. Is there anything which would read a Java class definition and generate an XSD file, plus Java classes to allow me to read an object from XML? It sounds like the kind of thing that should be out there somewhere but I don't really know what to search for. Thanks for any tips.

Share this post


Link to post
Share on other sites
Advertisement
If you don't mind writing the code yourself you can use the reflection API to write some generic code which accepts a Class and some xml and converts it into a loaded object. Iterating over all the members and finding their associated xml attribute isn't that hard and works very well. I use this method for my data-driven xml stuff.

If you really wanted to go with generated code rather than a reusable runtime method, then you could use the reflection api to avoid parsing the class yourself.

HTH

Share this post


Link to post
Share on other sites
I highly recommend xstream. (http://xstream.codehaus.org/)

It uses java's reflection to automagically map XML to objects and back. Not the best for an enterprise solution but works well for simple data exchange/serialization.

Share this post


Link to post
Share on other sites
I don't want to write anything... and I'd quite like an XSD schema so that someone else can generate the XML without me having to trust them!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!