users@jaxb.java.net

Re: Java objects to XML Mapping.

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 8 Jul 2009 08:38:42 +0200

Hi,

> 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.
> If JAXB is not the best way to achieve this, please suggest alternate
> technology.

JAXB usually does not generate unnecessary code. If you got 120+
classes this means that you schema needs all these classes to be
_fully_ represented in Java.

I guess your problem is that from all these 120+ classes you have
usage for just a couple, the rest is of no interest for you.

My suggestions would be:
1. Just use these couple of classes and ignore the rest 118+
schema-derived classes.
2. Do not generate classes from schema. Write and annotate them manually.

If you really need just a couple of classes, the second option seems
to be quite easy to implement.

Bye.
/lexi