Hi Laslo,

You are correct, the name of the root element is ignored during
unmarshalling if you pass in a root class. I am actually surprised more
people don't complain about this...

There is a current work around:

If you don't want the root element to be ignored, try this:

ClassDescriptorResolverImpl cdr = new ClassDescriptorResolverImpl();
cdr.resolve(Root.class);

Unmarshaller unmarshaller = new Unmarshaller((Class)null);
unmarshaller.setResolver(cdr);
unmarshaller.unmarshal(....);

That should work, for now. 

We will fix the issue soon.

Thanks,

--Keith



"BEDNARIK,LASLO (HP-Germany,ex1)" wrote:
> 
> Hi Arnaud,
> 
> thanks for your reply.
> 
> Regarding the descriptors: yes, they are all compiled
> when I run my test code.
> Regarding the Root.unmarshal method: it doesn't change
> the behaviour at all. I also don't see how it could
> as it is basically doing the same thing internally
> that I did in my code so far (calling default
> Unmarshaller instance and casting to my root
> element class).
> Anyway, I tried it and the result is the same.
> 
> I have attached an archive with my test setup.
> It is based on ANT and only one thing needs to be
> adjusted to run it:
> 
> - point the classpath in the "init" target to your
>   castor.jar and xerces.jar (I used 0.9.3.9 for testing).
> 
> Then run "ant generate".
> 
> Bye,
> 
> Laslo
> 
> -----Original Message-----
> From: Arnaud Blandin [mailto:[EMAIL PROTECTED]]
> Sent: Friday, January 25, 2002 12:44 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [castor-dev] Root element of input xml ignored
> 
> Hi Laslo,
> 
> Have you compiled your descriptors? Besides you should use the
> unmarshall method that comes with the Root class.
> Hope this helps,
> 
> Arnaud
> 
> > -----Original Message-----
> > From: BEDNARIK,LASLO (HP-Germany,ex1) [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, January 24, 2002 3:04 PM
> > To: [EMAIL PROTECTED]
> > Subject: [castor-dev] Root element of input xml ignored
> >
> > Hi,
> >
> > I instantiate an Unmarshaller passing the class that was generated for
> the
> > root element of my schema
> > and use it to read an XML document. I would expect that if the
> > Unmarshaller
> > returns an instance of
> > the root element class the XML document was correct. However the
> actual
> > root
> > tag can be anything - it
> > is always accepted (marshalling validation is set to true in
> > castor.properties).
> >
> > This seems to be a bug / missing feature.
> >
> > Bye,
> >
> > Laslo
> >
> >
> > E.g. the following XML document is accepted when read with an
> Unmarshaller
> > (passing Root.class to it):
> >
> > DOCUMENT
> >
> >    <?xml version="1.0" encoding="UTF-8"?>
> >    <Foobar>
> >        <Element1>A</Element1>
> >        <Element2>B</Element2>
> >        <Element3>C</Element3>
> >    </Foobar>
> >
> > SCHEMA
> >
> >    <?xml version = "1.0" encoding = "UTF-8"?>
> >    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"; >
> >
> >    <xsd:element name="Root">
> >    <xsd:complexType>
> >       <xsd:sequence>
> >          <xsd:element name="Element1" type="xsd:string" />
> >          <xsd:element name="Element2" type="xsd:string" />
> >          <xsd:element name="Element3" type="xsd:string" />
> >       </xsd:sequence>
> >    </xsd:complexType>
> >    </xsd:element>
> >
> >    </xsd:schema>
> >
> >
> > CODE SNIPPET
> >
> >          org.exolab.castor.xml.Unmarshaller um = new
> > org.exolab.castor.xml.Unmarshaller(Root.class);
> >          InputStreamReader ir = new InputStreamReader( new
> > FileInputStream(
> > "in1.xml"),"UTF-8");
> >          Root r = (Root)um.unmarshal(ir);
> >          ir.close();
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >       unsubscribe castor-dev
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev
> 
>   ------------------------------------------------------------------------
>                             Name: root_element_test.zip
>    root_element_test.zip    Type: Zip Compressed Data (application/x-zip-compressed)
>                         Encoding: base64

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to