Xml String Parsing在android中没有响应

时间:2014-09-12 13:11:43

标签: android xml xml-parsing

我正在从以下链接解析xml字符串 Live Scores Rss

我使用了以下代码。我将条目显示在列表视图中。但我没有得到回应。有人建议如何得到回应。

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;
}

0 个答案:

没有答案