users@jaxb.java.net

Re: JAXB - Automatic creation of mandatory children

From: kr vijay <sagivijay_at_yahoo.com>
Date: Tue, 21 Sep 2004 04:07:06 -0700 (PDT)

Hi,
Is it possible to also unmarshal correctly from an
invalid xml (without some of the required elements)
without an exception being generated if i set a
similar validation handler?
Thanks,
Vijay
--- Aleksei Valikov <valikov_at_gmx.net> wrote:

> 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.
>
> As I said in my opinion there is currently a bug in
> RI. I hope this will
> be corrected quite soon.
>
> You _can_ actually disable validation on marshalling
> by providing your
> own event handler:
>
> marshaller.setEventHandler(new
> ValidationEventHandler()
> {
> public boolean handleEvent(ValidationEvent
> event)
> {
> return true;
> }
> });
> final Root root = objectFactory.createRoot();
> final ElementType element2 =
> objectFactory.createElementType();
> root.setElement2(element2);
>
> marshaller.marshal(root, System.out);
>
> Please note that this does not work for root
> elements currently (due to
> the problem that I described in another posting).
>
> 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!?
Declare Yourself - Register online to vote today!
http://vote.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