In order to Marshal/Unmarshall, you need to create a class 'hierarchy' identical to that of the XML document. So, for example:
<tests>
<lib-data>
<library>Library</library>
<count>64018</count>
<test-data>
<title>Book title1</title>
<book>Book Name1</book>
<count>5</count>
</test-data>
<test-data>
<title>Book title2</title>
<book>Book Name3</book>
<count>5</count>
</test-data>
<test-data>
<title>Book title3</title>
<book>Book Name3</book>
<count>4</count>
</test-data>
</lib-data>
</tests>
I would create a 'tests' class with an single attribute - an ArrayList of 'lib-data' classes.
Within each lib-data class I would then create a String field called library, an int field called count, and an ArrayList of 'test-data' classes.
For each test data class I'd then create String title and book attributes and an int count attribute.
From there, just add the correct @XmlRootElement (before each class) and @XmlElement (before each attribute) annotation. After that point you can use Jaxb to do the actual marshaling and unmarshalling.
Edit:
Sorry, your question was very open ended so I was unsure as to how much you've created.
XML annotation is pretty straight forward, it would look like this for the 'tests' class:
@XmlRootElement
public class Tests {
@XmlElement(name="lib-data")
ArrayList<LibData> libData;
public Tests()
{
this.libData = new ArrayList<LibData>()
}
public ArrayList<LibData> getLibData() {
return this.libData;
}
public void setLibData(ArrayList<LibData> libData) {
this.libData = libData;
}
}
I would also create a 'MarshalHandler' class which hides the implementation details of marshalling and unmarshalling:
public class MarshalHandler {
private JAXBContext jc;
private Unmarshaller unmarshaller;
private Marshaller marshaler;
public MarshalHandler(){
jc = JAXBContext.newInstance(Tests.class);
unmarshaller = jc.createUnmarshaller();
marshaler = jc.createMarshaller();
}
public Test unmarshall(File f){
return (Tests) unmarshaller.unmarshal(f);
}
public void marshal(Tests t, String fileLoc){
OutputStream os = new FileOutputStream(fileLoc);
marshaler.marshal(t, os);
os.flush();
os.close();
}
}
(I haven't compiled or tested that code. It likely contains a mistake or two and definitely does not account for exceptions)
Now, how you handle the details of your MarshalHandler are totally up to you and will be influenced by the overall design of your program. For example, you may want your marshal method to return a StreamResult instead of saving to a predetermined fileLoc. Maybe you're grabbing this SOAP response and saving it as a byte array, in which case it would be nice to be able to pass that array directly to your unmarshall method. But, it's hard to say without more details.