This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am creating a simple Web Service. For the time being, I just want to have 3 or 4 Java object instances that will persist, that I can perform queries on. I want to have these instances stored in an XML file which I can read and write to.
Right now my problem is writing the objects to XML.
It seems like the best way to go about doing this is to create a class for each object in Java, then in a driver of some sort create instances of these objects, and write them to XML using JAXB.
I've read some tutorials on JAXB and with the help of Netbeans' generated code for marshalling, I have managed to write one instance to XML. My question is, what is the best way to write a group of instances into one XML file? Do I need to write a class for an object that represents a collection of the objects (for example, I want to store a group of "Book" objects, do I need to write a "BookList" class, and write one instance of "BookList" using JAXB)?
I have also read that for JAXB to work I need to have an XML schema, an "xsd" file. Is this something I write myself?
I am fairly new to XML so any help would be appreciated.
If you just want a simple way to turn Java objects into XML, there are existing options, such as java.beans.XMLEncoder and XMLDecoder, which are part of the core API, or a 3rd-party library such as XStream (which I think is free).