users@jaxb.java.net

Re: Unmarshalling of enums with whitespace characters

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 14 Dec 2010 19:12:44 +0100

Ah, yes - I didn't realize that the XML has multiple spaces between
"natuerliche" and "Person". This is violating the definition of xs:token,
and the validating SW should throw an exception. But, strangely enough,
everything works fine if you use xs:string instead of xs:token. Since you
are enumerating the expeceted values anyway, there isn't much point in using
xs:token, is there?

-W



On 14 December 2010 16:49, gernot999 <gernot.piberger_at_gmx.de> wrote:

>
> Wolfgang,
>
> unfortunately that's exactly our problem. We set the schema on the
> unmarshaller to enable validation, but do not receive an exception when
> unmarshalling.
>
> Gernot
>
>
>
>
>
> Wolfgang Laun-2 wrote:
> >
> > If you set the schema and unmarshal, you should see an error resulting
> > from
> > the validation
> > done during unmarshalling. (There isn't a separate validation.) Here's
> the
> > code
> > to use:
> >
> > JAXBContext jc = JAXBContext.newInstance( PACKAGE );
> > Unmarshaller m = jc.createUnmarshaller();
> > //assign a schema to the unmarshaller
> > SchemaFactory factory =
> > SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
> > try{
> > Schema schema = factory.newSchema( new File( SCHEMA ));
> > m.setSchema(schema);
> > } catch(SAXException e) {
> > e.printStackTrace();
> > // return or whatever
> > }
> >
> > Person obj = null;
> > try {
> > obj = (Person)m.unmarshal( new File( XMLIN ) );
> > System.out.println( obj.getVorname() );
> > System.out.println( obj.getNachname() );
> > System.out.println( obj.getTyp() ); }
> > catch( Exception e ){
> > System.err.println( "-----------------unmarshal error" );
> > e.printStackTrace();
> > }
> >
>
> --
> View this message in context:
> http://old.nabble.com/Unmarshalling-of-enums-with-whitespace-characters-tp30398383p30403910.html
> Sent from the java.net - jaxb users mailing list archive at Nabble.com.
>
>