users@jaxb.java.net

Re: Unmarshalling Question

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Thu, 04 Jan 2007 10:41:31 -0800

Frank Kumro wrote:
> Hello,
>
> I am just starting out with JAXB and I have a question about an
> unmarshalling that I am trying to do. The steps I used are below to avoid
> any confusion (I hope).
>
> Basically I have a xml digital signature schema (
> http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd)
> and I have an xml digital signature generated and saved. I want to
> unmarshal the file using JAXB so I can work with it, I used the xjc jar to
> generate the classes needed. After following some tutorials I hit a brick
> wall during my coding process, whats the class name I use for my
> unmarshaller? The code below is showing my issue, all the examples have the
> root node named Item and then they use the "Item" class and a cast. What
> would I use?
>
> [code]
> private void unmarshal() throws JAXBException
> {
> Object o = unmarshaler.unmarshal(xmlFile);
> }
> [/code]
>
> I realize I cannot use an Object because I cannot access my data then. Any
> point in the correct direction would be great! Thanks in advance...

You'll cast that to the class that corresponds to the root element of
your document. If you are not sure, run

   System.out.println( unmarshaller.unmarshal(xmlFile).getClass() );

... to find out what class it is.



-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com