Hey guys,
I posted a similar thread earlier on in the month, but there seemed to be some sort of confusion regarding what I was actually asking.
For one of our modules we were asked to create a program which takes some objects and stores them into files using three different methods – Text, XML and Serializable.
I was able to do Serializable and Text, but I seem to be having some confusion with XML.
I have two classes, Books and Authors.
Books are set into the Author using names – so the code looks something akin to this..
Book class -
Instance = private Author who;
and in the Author class..
.
This is what the XML code looks like..
This is found in the 'model' class which takes user input and stores them into ArrayLists.
However, whenever I save in XML I get..
I hope that's enough information regarding my issue, if any of you can help then I'll forever be thankful!
Thanks
Also, all of the code can be found here.
I posted a similar thread earlier on in the month, but there seemed to be some sort of confusion regarding what I was actually asking.
For one of our modules we were asked to create a program which takes some objects and stores them into files using three different methods – Text, XML and Serializable.
I was able to do Serializable and Text, but I seem to be having some confusion with XML.
I have two classes, Books and Authors.
Books are set into the Author using names – so the code looks something akin to this..
Book class -
Instance = private Author who;
Code:
public void setAuthor(ArrayList<Author> authors) {
this.who = who;
}
and in the Author class..
.
Code:
public void setBooks(ArrayList<Book> books) {
this.books = books;
}
public ArrayList<Book> getBooks() {
return books;
}
This is what the XML code looks like..
Code:
public void writeXML(String fn) throws IOException {
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
new FileOutputStream(fn)));
encoder.writeObject(this);
encoder.close();
}
This is found in the 'model' class which takes user input and stores them into ArrayLists.
However, whenever I save in XML I get..
Code:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.7.0_09" class="java.beans.XMLDecoder">
<object class="Model"/>
</java>
I hope that's enough information regarding my issue, if any of you can help then I'll forever be thankful!
Thanks
Also, all of the code can be found here.