Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         try {
  3.             JAXBContext context = JAXBContext.newInstance(BookList.class);
  4.             Unmarshaller um = context.createUnmarshaller();
  5.             FileReader file = new FileReader("books.xml");
  6.             BookList books = (BookList) um.unmarshal(file);
  7.             file.close();
  8.             BookManager bm = new BookManager(books.getBooks());
  9.             List<Book> javaBooks = bm.searchByTitle("Java");
  10.  
  11.             Book lab_book = new Book("lab_book", "Laboratorium: Java i XML", "Dawid Gliński", "12345678", 2014, "ZUT", 1000);
  12.             javaBooks.add(lab_book);
  13.             Marshaller marshaller = context.createMarshaller();
  14.             books.setList(javaBooks);
  15.             marshaller.marshal(books, new File("lab3.xml"));
  16.         } catch (JAXBException ex) {
  17.             ex.printStackTrace();
  18.         } catch (FileNotFoundException ex) {
  19.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  20.         } catch (IOException ex) {
  21.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  22.         }
  23.  
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement