users@jaxb.java.net

RE: Java objects to XML Mapping.

From: <varun.rally_at_rbs.com>
Date: Wed, 8 Jul 2009 07:46:20 +0100

Thanks for the reply lexi.

Actually we need to populate each and every element inside the XML. JAXB has created a class for each element in XML. Hence if we go with the first approach, then we will definitely require all 120+ classes.

2nd approach looks better to me as well, but I don't have any idea on how to achieve it. Can you please through some more light on the second option.

For Example, let us say there is tag <employeeName>. Its value needs to be populated from some class for example..BankAccountDetails and the field name is ename. Then how do we proceed in the right direction.

Also, please share some internet references for the 2nd option that I can look at, learn and implement.

Thanks


-----Original Message-----
From: aleksei.valikov_at_gmail.com [mailto:aleksei.valikov_at_gmail.com] On Behalf Of Aleksei Valikov
Sent: 08 July 2009 12:09
To: users_at_jaxb.dev.java.net
Subject: Re: Java objects to XML Mapping.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net


***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312. Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority.
 
This e-mail message is confidential and for use by the
addressee only. If the message is received by anyone other
than the addressee, please return the message to the sender
by replying to it and then delete the message from your
computer. Internet e-mails are not necessarily secure. The
Royal Bank of Scotland plc does not accept responsibility for
changes made to this message after it was sent.

Whilst all reasonable care has been taken to avoid the
transmission of viruses, it is the responsibility of the recipient to
ensure that the onward transmission, opening or use of this
message and any attachments will not adversely affect its
systems or data. No responsibility is accepted by The
Royal Bank of Scotland plc in this regard and the recipient should carry
out such virus and other checks as it considers appropriate.

Visit our website at www.rbs.com

***********************************************************************************