/** * @author Hyacinthe MENIET * Created on 15 juil. 07 */ package net.dotmyself.j2xml; import java.io.FileReader; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; /** * Unmarshalles the given XML Document. */ public class XML2Java { /** * The main method. * @param args the path to file to read. * @throws Exception */ public static void main(String[] args) throws Exception { if(args == null || args.length < 1) { throw new IllegalArgumentException("You must indicate a path to file to read"); } String fileName = args[0]; // Unmarshalles the given XML file to objects JAXBContext context; context = JAXBContext.newInstance("net.dotmyself.j2xml"); Unmarshaller unmarshaller = context.createUnmarshaller(); Rentals rentals = (Rentals) unmarshaller.unmarshal(new FileReader(fileName)); List listOfRentals = rentals.getRental(); // Displays objects for(Rental rental : listOfRentals){ System.out.println("Type="+rental.getType()+", " +"User="+rental.getUser()+", " +"Title="+rental.getTitle()+", " +"Begin date="+rental.getBegindate()); } } }