I am using XStream to convert XML string to Java Object.
I have a huge set of data but I am posting the minimal code below:
XStream xstream = new XStream(new StaxDriver());
xstream.alias("data", DetList.class);
xstream.alias("i", Details.class);
String s = new String("<data>\n"
+"\t<i Name='asia' type='continent' id='11'></i>\n"
+"\t<i Name='africa' type='continent' id='12'></i>\n"
+"\t<i Name='japan' type='country' id='13'></i>\n"
+"</data>");
System.out.println(s);
DetList data = (DetList) xstream.fromXML(s);
When I debug, data is always null.
Here is my DetList class:
public class DetList {
private List<Details> detlist;
public List<Details> getDetlist() {
return detlist;
}
public void setDetlist(List<Details> detlist) {
this.detlist = detlist;
}
}
And my Details class:
public class Details {
private String Name;
private String type;
private String id;
//Getters and Setters are here.
}
data is null which is supposed to contain the list of i.
How can I get it to work?
namevariable? Also it should benameistead ofName@attributes, your question has multiple errors . One is that it is expectingitemsinstead of attributes in the<i> </i>element.