I'm trying to get the name and reading type="alpha".
I'm a beginner and English is not my first language, please pardon me. I've read about DOM, SAX, Simple, other StackOverflow posts, other samples but I don't understand and will like to learn about XMLPullParser in this case.
Sample XML below:
<feed>
<title>Title</title>
<item>
<entry>
<name>Name1</name>
<record date="20001231">
<reading type="alpha" value="100"/>
<reading type="beta" value="200"/>
</record>
</entry>
<entry>
<name>Name2</name>
<record date="20001231">
<reading type="alpha" value="300"/>
<reading type="beta" value="400"/>
</record>
</entry>
</item>
</feed>
I've read this: http://developer.android.com/training/basics/network-ops/xml.html and the sample code works for the sample XML above without the <item> tags to get the name and record date.
private List<Entry> readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
List<Entry> entries = new ArrayList<Entry>();
parser.require(XmlPullParser.START_TAG, ns, "feed");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
if (parser.getName().equals("entry")) {
entries.add(readEntry(parser));
} else {
skip(parser);
}
}
return entries;
}
What I've tried with the presence of <item> tags (but does not work) is:
private List<Entry> readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
List<Entry> entries = new ArrayList<Entry>();
parser.require(XmlPullParser.START_TAG, ns, "feed");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
if (parser.getName().equals("item")) {
parser.next();
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
if (parser.getName().equals("entry")) {
entries.add(readEntry(parser));
} else {
skip(parser);
}
}
} else {
skip(parser);
}
}
return entries;
}
If I can solve that, I will be able to read the name and record date, but what I'm trying to get is the name and reading type="alpha", which I don't know how to get the nested reading type="alpha".
Many thanks in advance.