Tuesday, August 14, 2012

Binding with JAXB


1) Get a xsd from an xml.
http://www.freeformatter.com/xsd-generator.html#ad-output


2) Generate the Java Objects
xjc.sh -p com.package.name books.xsd -d workfolder


3) Process it in Java

        JAXBContext jc = JAXBContext.newInstance("com.package.name");
   
 Unmarshaller unmarshaller = jc.createUnmarshaller();
   
 Collection collection = (Collection) unmarshaller.unmarshal(new File("src/books.xml"));



No comments:

Post a Comment