users@jaxb.java.net

Re: question regarding unmarshal an element of XML

From: Qingtian Wang <qingtian.wang_at_gmail.com>
Date: Mon, 5 Nov 2007 17:02:26 -0600

Lexi- Thanks so much!!

On 11/5/07, Aleksei Valikov <valikov_at_gmx.net> wrote:
> Hi
>
> > ====
> >
> > Hi,
> >
> > I should be able to unmarshal a sub-element of XML using the unmarshal
> > method, right?
> >
> > Here's my problem: I am using the latest 2.1 impl.
> >
> > I bound my XSDs into jaxb classes
> >
> > mypack/BoundBean1.java
> > mypack/BoundBean2.java
> > ....
> >
> > Then in my client class, I tried to unmarshal a sub-Element of XML per
> > BoundBean2.xsd like this:
> >
> > ....
> > (Bean2.SomeElement) jc.createUnmarshaller().unmarshal(new
> > StringReader(xmlElementStringOfBoundBean2));
> > ....
> >
> > I got an exception like this:
>
> ...
>
> See this:
> http://java.sun.com/webservices/docs/2.0/api/javax/xml/bind/Unmarshaller.html#unmarshalByDeclaredType
>
> You'll need to do something like:
>
> unmarshall(mySource, Bean2.SomeElement.class);
>
> You'll get a JAXBElement where value is the value (Bean2.SomeElement)
> you expect.
>
> 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
>
>