SringSring

Tuesday, 28 October 2014

Read data from XMl using JAXB in java

package Com.Srini.JaxB;

import java.io.File;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

public class JAXBExampleXmlToObject {
public static void main(String[] args) {

try {

File file = new File("E:\\file.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);

Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Customer customer = (Customer) jaxbUnmarshaller.unmarshal(file);
System.out.println(customer.name);

 } catch (JAXBException e) {
e.printStackTrace();
 }

}
}

No comments:

Post a Comment