Integracja aplikacji Ćwiczenie 4
books. xml.
try {
JAXBContext context = JAXBContext.newlnstance(BookList.class); Unmarshaller um = context.createUnmarshaller();
FileReader fr = new FileReader("books.xml");
BookList bl = (BookList) um.unmarshal(fr);
fr.closeO ;
} cateh (JAXBException e) { e.printStackTrace() ;
) catch (IOException e) ( e.printStackTrace() ;
public static void main(String[] args) { try {
JAXBContext context = JAXBContext.newlnstance(BookList.class); Unmarshaller um = context.createUnmarshaller();
FileReader file = new FileReader("books.xml");
BookList books = (BookList)um.unmarshal(file);
file.close();
BookManager bm = new BookManager( books.getBooks() );
List<Book> bs = bm.searchByTitle("Java");
System.out.println(bs);
} catch (Exception ex) (
ex.printStackTrace() ;