[Simple-support] Getting null for sublist
Brought to you by:
niallg
|
From: Saul K. <sb...@ny...> - 2011-04-13 23:45:27
|
Hi,
Please Help.
I having trouble going get sub lists
I just want to get the 1st def in this xml file and I cant get a "
partofspeech" list to show up
Thank you,
Saul
Code for in main:
String xmlData = retrieve(url);
Serializer serializer = new Persister();
Reader reader = new StringReader(xmlData);
Dictionary d = serializer.read(Dictionary.class, reader,
false);
Log.d(theToyActivity.class.getSimpleName(),
d.toString());
System.out.println(d.getQuery());
System.out.println(d.getTotalResults());
System.out.println("Entry list size: "
+ d.getEntry().size());
// System.out.println(d.getEntry());
List<Entry> list = d.getEntry();
for (Entry e : list) {
System.out.println("Entry: " + e.getDisplay() + " "
+ e.getId() + " " + e.getPron());
XML:
<?xml version="1.0" encoding="UTF-8" ?>
<dictionary query="good" totalresults="9">
<entry source="pdict" id="4086801">
<display_form >
<![CDATA[good]]>
</display_form>
<pron
audiofile="http://static-api.dictionary.com/dictstatic/dictionary/audio/luna
WAV/G02/G0255000.wav">
<![CDATA[[g<i>oo</i>d]]]>
</pron>
<partofspeech pos="adjective">
<defset>
<def charcnt="17" defno="1">
<![CDATA[morally excellent]]>
</def>
<def charcnt="27" defno="2">
<![CDATA[of high or adequate quality]]>
</def>
<def charcnt="12" defno="3">
<![CDATA[well-behaved]]>
</def>
<def charcnt="4" defno="4">
<![CDATA[kind]]>
</def>
<def charcnt="5" defno="5">
<![CDATA[valid]]>
</def>
<def charcnt="9" defno="6">
<![CDATA[favorable]]>
</def>
</defset>
</partofspeech>
<partofspeech pos="noun">
<defset>
<def charcnt="19" defno="7">
<![CDATA[profit or advantage]]>
</def>
<def charcnt="6" defno="8">
<![CDATA[virtue]]>
</def>
<def charcnt="11" defno="9">
<![CDATA[possessions]]>
</def>
</defset>
</partofspeech>
</entry>
</dictionary>
Classes
package define;
import java.util.ArrayList;
import java.util.List;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import define.Entry;
@Root
public class Dictionary {
@Attribute
private String query;
@Attribute
private String totalresults;
@ElementList(inline = true, name = "entry")
private List<Entry> list;
public Dictionary() {
super();
}
public Dictionary(String query, String totalresults, List<Entry> list) {
this.query = query;
this.totalresults = totalresults;
this.list = list;
}
public String getQuery() {
return query;
}
public String getTotalResults() {
return totalresults;
}
public List getEntry() {
return list;
}
}
--
package com.sbk.xml;
import java.util.List;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Default;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root
public class Entry {
@Attribute
private String id;
@Element(required = false)
private String display_form;
@Element(required = false)
private String pron;
@ElementList(inline = true, required = false, name = "partofspeech",
type=PartOfSpeech.class)
private List<PartOfSpeech> partofspeech;
public String getId() {
return id;
}
public String getDisplay() {
return display_form;
}
public String getPron() {
return pron;
}
public List getPartOfSpeech() {
return partofspeech;
}
}
--
package com.sbk.xml;
import java.util.List;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
@Root
public class PartOfSpeech {
@Attribute(required = false)
private String pos;
@ElementList(inline = true, required = false, name="defset")
private List<Defset> defset;
public String getPos(){
return pos;
}
public List getDefset() {
return defset;
}
}
--
package com.sbk.xml;
import java.util.List;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;
public class Defset {
@ElementList(inline = true, required = false, name="def")
private List<Def> def;
// @Element(required = false, name="def")
// private List<Def> def;
public List getDefList() {
return def;
}
}
--
package com.sbk.xml;
import org.simpleframework.xml.Element;
public class Def {
@Element(required = false)
private String def;
public String getDef(){
return def;
}
}
|