• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Objects to XML Mapping

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have few 2 java objects which are populated from 2 different tables. I also have a predefined XML schema in place. The end goal is to generate a XML that confirms to the schema and has data populated from these 2 java objects.

What would be the best API to create XML that confirms to a schema and has data populated from these 2 java objects. I have already tried JAXB, but the problem with that approach is that JAXB generated 120+ Java Classes for 1 XML, which is a huge number, though the actual data we have exists in 2 different objects only.

Please suggest a good API to achieve this functionality.
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rakesh,

I have already used JAXB and was VERY happy with it! It automatically handles the marshalling and unmarshalling process, validation etc. You don't have to parse or convert common Java data types to or from XML and so on.

By default the JAXB generator creates Java classes for all elements of an existing XML schema. So in your case I suspect that the XML schema is not only used for your relatively small use case?!? The generator can be configured and adapted to your requirements and needs, although I don't know how to prevent that it generates classes for all schema elements (or if it's even possible to restrict the generating process). You should take a look at the documentation as JAXB is really a comfortable and robust way to transform data from and to XML ;-)

Marco
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JAXB is for the birds ... try Apache XMLBeans instead

http://xmlbeans.apache.org/
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic