Exemplo n.º 1
0
 private void endTag(String name) {
   if (ITEM.equals(name)) {
     feed.addItem(currentItem);
     currentItem = Item.NONE;
   }
   state = ParseState.NONE;
 }
Exemplo n.º 2
0
  // parsing the XML
  public void parseXMLAndStoreIt(XmlPullParser myParser) {
    int event;
    String text = null;
    // Create item
    try {
      event = myParser.getEventType();
      Item item = null;
      boolean checkItem = true;
      boolean newItem = false;

      while (event != XmlPullParser.END_DOCUMENT) {
        String name = myParser.getName();
        if (checkItem) {
          item = new Item();
          checkItem = false;
        }

        switch (event) {
          case XmlPullParser.START_TAG:
            if (name.equals("item")) {
              newItem = true;
            }
            break;
          case XmlPullParser.TEXT:
            text = myParser.getText();
            break;
          case XmlPullParser.END_TAG:
            switch (name) {
              case "title":
                if (newItem) {
                  item.setTitle(text);
                }
                break;
              case "description":
                if (newItem) {
                  item.setDescription(text);
                }
                break;
              case "link":
                if (newItem) {
                  item.setLink(text);
                }
                break;
            }
            break;
        }
        // add to an array list
        if (item.itemReady()) {
          feed.addItem(item);
          newItem = false;
          checkItem = true;
        }
        event = myParser.next();
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }