For this simple element, I would create a class called "Categories:
import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Categories { protected String key_0; protected String key_1; protected String key_2; public String getKey_0() { return key_0; } public void setKey_0(String key_0) { this.key_0 = key_0; } public String getKey_1() { return key_1; } public void setKey_1(String key_1) { this.key_1 = key_1; } public String getKey_2() { return key_2; } public void setKey_2(String key_2) { this.key_2 = key_2; } }
Then in the main method or so I would create an unmarshaller:
JAXBContext context = JAXBContext.newInstance(Categories.class); Unmarshaller um = context.createUnmarshaller(); Categories response = (Categories) um.unmarshal(new FileReader("my.xml"));
To be able to retrieve all the objects, I think that I would put all the elements inside the root element in a new xml file and write a class for this root element with the annotation @XmlRootElement .
Hope this helps, mman
source share