Friday, 12 September 2014

Xml String Parsing giving no response in android



I am parsing xml string from the below link Live Scores Rss


I have used the following code. I am displaying the entries into a listview. But I am getting no response. anyone suggest how to get response.



private List<Entry> readFeed(XmlPullParser parser) throws XmlPullParserException, IOException {
List<Entry> entries = new ArrayList<Entry>();

parser.require(XmlPullParser.START_TAG, ns, "links");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
// Starts by looking for the entry tag
if (name.equals("match")) {
entries.add(readEntry(parser));
} else {
skip(parser);
}
}
return entries;
}
public static class Entry {
public final String state;
public final String Tm;
public final String Tme;

private Entry(String title, String summary, String link) {
this.state = title;
this.Tm = summary;
this.Tme = link;
}
}

private Entry readEntry(XmlPullParser parser) throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, ns, "match");
String title = null;
String summary = null;
String link = null;
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("state")) {
title = readTitle(parser);
} else if (name.equals("Tm")) {
summary = readSummary(parser);
} else if (name.equals("Tme")) {
link = readLink(parser);
} else {
skip(parser);
}
}
return new Entry(title, summary, link);
}

// Processes title tags in the feed.
private String readTitle(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "title");
String title = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "title");
Log.v("", "======response====="+title);
return title;
}

// Processes link tags in the feed.
private String readLink(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "link");
String link = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "link");
return link;
}

// Processes summary tags in the feed.
private String readSummary(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "summary");
String summary = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "summary");
return summary;
}

// For the tags title and summary, extracts their text values.
private String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
String result = "";
if (parser.next() == XmlPullParser.TEXT) {
result = parser.getText();
parser.nextTag();
}
return result;
}

No comments:

Post a Comment