Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- try {
- JAXBContext context = JAXBContext.newInstance(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> javaBooks = bm.searchByTitle("Java");
- Book lab_book = new Book("lab_book", "Laboratorium: Java i XML", "Dawid Gliński", "12345678", 2014, "ZUT", 1000);
- javaBooks.add(lab_book);
- Marshaller marshaller = context.createMarshaller();
- books.setList(javaBooks);
- marshaller.marshal(books, new File("lab3.xml"));
- } catch (JAXBException ex) {
- ex.printStackTrace();
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement