Для этого простого элемента я бы создал класс с именем 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;
}
}
Затем в основном методе я бы создал unmarshaller:
JAXBContext context = JAXBContext.newInstance(Categories.class);
Unmarshaller um = context.createUnmarshaller();
Categories response = (Categories) um.unmarshal(new FileReader("my.xml"));
// access the Categories object "response"
Toбыть в состоянии получить все объекты, я думаю, я бы поместил все элементы в корневой элемент в новый XML-файл и написал класс для этого корневого элемента с аннотацией @XmlRootElement
.
Надеюсь, это поможет, мман1010 *