Пример #1
0
 private void parseChannel(Feed feed, KXmlParser parser)
     throws XmlPullParserException, IOException {
   while (parser.getEventType() != XmlPullParser.END_TAG) {
     final String nodeName = parser.getName();
     if ("title".equals(nodeName)) {
       feed.setTitle(parser.nextText());
     } else if ("link".equals(nodeName)) {
       feed.setLink(parser.nextText());
     } else if ("description".equals(nodeName)) {
       feed.setDescription(parser.nextText());
     } else if ("language".endsWith(nodeName)) {
       feed.setLanguage(parser.nextText());
     } else if ("pubDate".endsWith(nodeName)) {
       feed.setPubDate(parser.nextText());
     } else if ("lastBuildDate".endsWith(nodeName)) {
       feed.setLastBuildDate(parser.nextText());
     } else if ("generator".endsWith(nodeName)) {
       feed.setGenerator(parser.nextText());
     } else if ("managingEditor".endsWith(nodeName)) {
       feed.setManagingEditor(parser.nextText());
     } else if ("webMaster".endsWith(nodeName)) {
       feed.setWebMaster(parser.nextText());
     } else if ("item".endsWith(nodeName)) {
       parseItem(feed, parser);
     } else if ("image".endsWith(nodeName)) {
       feed.setImage(parser.nextText());
     } else {
       parser.skipSubTree();
     }
     parser.nextTag();
   }
 }
Пример #2
0
  private void parseItem(Feed feed, KXmlParser parser) throws IOException, XmlPullParserException {
    final Entry entry = new Entry();
    feed.getEntries().add(entry);

    parser.nextTag();

    while (parser.getEventType() != XmlPullParser.END_TAG) {
      final String nodeName = parser.getName();

      if ("title".equals(nodeName)) {
        entry.setTitle(parser.nextText());
      } else if ("link".equals(nodeName)) {
        entry.setLink(parser.nextText());
      } else if ("description".equals(nodeName)) {
        entry.setDescription(parser.nextText());
      } else if ("author".equals(nodeName)) {
        entry.setAuthor(parser.nextText());
      } else if ("category".equals(nodeName)) {
        entry.setCategory(parser.nextText());
      } else if ("comments".equals(nodeName)) {
        entry.setComments(parser.nextText());
      } else if ("enclosure".equals(nodeName)) {
        entry.setEnclosure(parser.nextText());
      } else if ("guid".equals(nodeName)) {
        entry.setGuid(parser.nextText());
      } else if ("pubDate".equals(nodeName)) {
        entry.setPubDate(parser.nextText());
      } else if ("source".equals(nodeName)) {
        entry.setSource(parser.nextText());
      } else {
        parser.skipSubTree();
      }
      parser.nextTag();
    }
  }