The following code works for me, pay particular attention to the following two elements:
- empty constructor in ALL.java
- That the list has the annotation
inline=true
ALL.java:
import org.simpleframework.xml.ElementList; import org.simpleframework.xml.Root; import org.simpleframework.xml.Serializer; import org.simpleframework.xml.core.Persister; import java.io.File; import java.util.List; @Root(name="ALL") public class ALL { @ElementList(entry="KAMP", inline=true) private List<KAMP> kamp; public ALL(){}; public List<KAMP> getMatches() { return kamp; } public static void main(String...args) throws Exception { Serializer serializer = new Persister(); File example = new File("/Users/alfasin/Documents/workspace-sts-3.2.0.RELEASE/SimpleXML/src/kamp.xml"); ALL all = serializer.read(ALL.class, example); for(KAMP tmp : all.getMatches()){ System.out.println("ID: "+tmp.Id); System.out.println("MatchDate: "+tmp.MatchDate); System.out.println("Sqltid: "+tmp.Sqltid); System.out.println("----------"); } } }
KAMP.java
import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; @Root(name="KAMP",strict = false) public class KAMP { @Element(name = "ID", required = false) public String Id; @Element(name = "SQLTID", required = false) public String Sqltid; @Element(name = "DATO", required = false) public String MatchDate; }
OUTPUT
ID: 1 MatchDate: 2013-08-19 Sqltid: 1376881200 ---------- ID: 2 MatchDate: 2013-08-19 Sqltid: 1376881200 ----------
source share