create objects from xml which has muitiple classes using JAXB?

El3sili

New Member
I have xsd and xml file. first I have generated Java classes from xsd file ,that part has done and now I have to feed data into objects using xml ? I am using below code , but this is throwing JAXBException.\[code\] try { File file = new File("D:\\file.xml"); JAXBContext jaxbContext = JAXBContext.newInstance("com.jaxb.generated"); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); Employee empObj = (Employee) jaxbUnmarshaller.unmarshal(file); System.out.println(empObj.getName()); } catch (JAXBException e) { e.printStackTrace(); }\[/code\]and here is my xml file which contains two classes :\[quote\]\[code\] <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Employee> <name>John</name> <salary>5000</salary> </Employee> <Customer> <name>Smith</name> </Customer>\[/code\]\[/quote\]could somebody help me ?
 
Back
Top