users@jaxb.java.net

Re: Parse with StAX and map to JAXB objects using Reflection?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Mon, 30 Jul 2007 13:49:16 -0700

alioum wrote:
> Hi,
>
> I would like to use Reflection to map xml data I parsed with StAX to the
> JAXB classes I generated.
> The situation is:
> I habe 7 xsd: A.xsd, B.xsd, C.xsd, D.xsd, E.xsd, F.xsd, G.xsd
> I generated the JAXB classes successfully using JAXB 1.5 (I must use this
> version because I use java 1.4)
>
> Now, when I receive an XML file as an instance of one of the XSDs (e.g.
> A.xml), I parse it with StAX and would like to map the extracted data to the
> JAXB classes using Reflection. Doing so, I don't have to know what kind of
> xml file I receive. I began to implement such a solution using reflection,
> but it seems to be very complicated.
>
> Is there any library/tool/add-on or something that can help me solve my
> problem ?

JAXB2 makes this snap. There's Unmarshaller.unmarshal that takes
XMLStreamReader.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com