Parse 2 Levels of XML android



Please correct the table if it is wrong, ,I'm not entirely sure what to title this.


I am trying to parse my XML in android and i have code that should work, but the problem is there are multiple levels of tags i need to get into.


Here is an example of my XML:



<dsxout>
<uselessTag>unnecasary info</uselessTag>
<results>
<listing>
<title>I'm a Title</title>
<description>very amusing description</description>
</listing>
<listing>
...
</listing>
</results>
</dsxout>


Here is where my parsing gets stuck:



private List readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
List entries = new ArrayList();
Toast.makeText(getBaseContext(), "readFeed", Toast.LENGTH_SHORT).show();

parser.require(XmlPullParser.START_TAG, ns, "dsxout");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();


The line below just spits out the tag uselessTag and results



Toast.makeText(getBaseContext(), name, Toast.LENGTH_SHORT).show();

// Starts by looking for the entry tag
if (name.equals("listing")) {
entries.add(readEntry(parser));
} else {
skip(parser);
}
}
return entries;
}


The problem is it only reads to the second level of tags and not inside the results tag so it cannot find listing.


How do I go another level in while reading?


No comments:

Post a Comment