O'Reilly logo

Java EE Development with Eclipse by Deepak Vohra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unmarshalling an XML document

For unmarshalling the same XML document that we created in the previous section, create a Java class—JAXB2UnMarshaller.java. In the unmarshaller class create a JAXBContext object as in the previous section and create an Unmarshaller object using the createUnmarshaller() method:

JAXBContext jaxbContext = JAXBContext.newInstance("jaxbeclipse");
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();

For XML Schema validation we need to set an XML Schema on the Unmarshaller object. Create a SchemaFactory object using the static method newInstance(), a Schema object from the SchemaFactory object using the newSchema() method, and set the schema on the Unmarshaller object using the setSchema() method:

SchemaFactory schemaFactory ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required