ok seguendo i tuoi consigli ho risolto tutto.
codice:
@XmlRootElement(name = "book")
public class Libro {
private int id;
private String title;
private String author;
private String editor;
private String isbn;
private double price;
private String note;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getEditor() {
return editor;
}
public void setEditor(String editor) {
this.editor = editor;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
i libri:
codice:
@XmlRootElement(name = "books")
public class Libri {
ArrayList<Libro> listaLibri;
public void setListaLibri(ArrayList<Libro> book) {
this.listaLibri = book;
}
@XmlElement(name = "book")
public ArrayList<Libro> getListaLibri() {
return listaLibri;
}
}
creo la lista:
codice:
public class ExportXml {
public void createXml(JTable table, File file) throws JAXBException {
ArrayList<Libro> bookList = new ArrayList<>();
for (int row = 0; row < table.getRowCount(); row++) {
Libro bookModel = new Libro();
for (int column = 0; column < table.getColumnCount(); column++) {
bookModel.setId(Integer.parseInt(table.getValueAt(row, 0).toString()));
bookModel.setTitle(table.getValueAt(row, 1).toString());
bookModel.setAuthor(table.getValueAt(row, 2).toString());
bookModel.setEditor(table.getValueAt(row, 3).toString());
bookModel.setPrice(Double.parseDouble(table.getValueAt(row, 4).toString()));
bookModel.setIsbn(table.getValueAt(row, 5).toString());
bookModel.setNote(table.getValueAt(row, 6).toString());
}
bookList.add(bookModel);
}
Libri books = new Libri();
books.setListaLibri(bookList);
JAXBContext context = JAXBContext.newInstance(Libri.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(books, file);
}
}
grazie per gli ottimi consigli!!