users@jaxb.java.net

Re: JAXB - Automatic creation of mandatory children

From: kr vijay <sagivijay_at_yahoo.com>
Date: Tue, 21 Sep 2004 02:17:08 -0700 (PDT)

Hi,
Thanks for your reply.
I am forced to create all the mandatory children
because my XML will then become invalid. Moreover, I
get an exception when I try to marshal/unmarshal an
invalid XML.
JAXB need not guess the default values at all. Infact
all that I am doing right now is the following. To
create an element A which has B and C as mandatory
children:
ObjectFactory of = new ObjectFactory();
A a = of.newInstance(A.class);//0
B b = of.newInstance(B.class)//1
C c = of.newInstance(C.class)//2
A.setB(b);//3
A.setC(c);//4

Cant JAXB do lines 1,2,3,4 automatically so that all I
need to do then is just line 0.

Please also let me know if it is possible to
marshal/unmarshal an invalid xml incase I cant create
these mandatory children automatically.

Thanks a lot for your reply.
Regards,
Vijay

--- Aleksei Valikov <valikov_at_gmx.net> wrote:

> Hi.
>
> > I have a web-based application to edit an XML
> file. I
> > am using JAXB to convert my XML file to Java
> objects.
> >
> > I am facing a problem. Whenever I want to create a
> new
> > element, I am also forced to create all the
> mandatory
> > child elements and set them in the object for the
> new
> > element.
>
> Could you please elaborate on why are you forced to
> create all mandatory
> children.
>
> > This becomes a real pain since the number of
> elements
> > I create and the number of mandatory children each
> > element has is really huge, I am writing a lot of
> code
> > for creating and setting these objects.
> >
> > Is there a way in JAXB that creates all these
> > mandatory children automatically whenever I create
> the
> > parent object.
>
> Any idea how JAXB could guess the values for the
> mandatory children?
>
> > I assume this has got to do with the way the
> classes
> > are generated. At present, there is no such code
> > generated for creating mandatory children.
> >
> > Please let me know if this can be done by any
> means.
>
> Try disabling the validation.
>
> 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
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

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