Advertisement
Guest User

Feed_XMLHandler

a guest
Dec 24th, 2010
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. package com.duveaux.dekrant;
  2.  
  3. import java.net.URLEncoder;
  4.  
  5. import org.xml.sax.Attributes;
  6. import org.xml.sax.SAXException;
  7. import org.xml.sax.helpers.DefaultHandler;
  8.  
  9. public class Feed_XMLHandler extends DefaultHandler {
  10.  
  11.     Boolean currentElement = false;
  12.     String currentValue = null;
  13.     public static Feed_XMLList sitesList = null;
  14.  
  15.     public static Feed_XMLList getSitesList() {
  16.         return sitesList;
  17.     }
  18.  
  19.     public static void setSitesList(Feed_XMLList sitesList) {
  20.         Feed_XMLHandler.sitesList = sitesList;
  21.     }
  22.  
  23.     /** Called when tag starts ( ex:- <name>AndroidPeople</name>
  24.      * -- <name> )*/
  25.     @Override
  26.     public void startElement(String uri, String localName, String qName,
  27.             Attributes attributes) throws SAXException {
  28.  
  29.         currentElement = true;
  30.  
  31.         if (localName.equals("channel"))
  32.         {
  33.             /** Start */
  34.             sitesList = new Feed_XMLList();
  35.         }
  36.     }
  37.  
  38.     /** Called when tag closing ( ex:- <name>AndroidPeople</name>
  39.      * -- </name> )*/
  40.     @Override
  41.     public void endElement(String uri, String localName, String qName)
  42.             throws SAXException {
  43.  
  44.         currentElement = false;
  45.  
  46.         /** set value */
  47.         if (localName.equalsIgnoreCase("title"))
  48.             sitesList.setName(currentValue);
  49.         else if (localName.equalsIgnoreCase("link"))
  50.             sitesList.setLink(currentValue);
  51.         else if (localName.equalsIgnoreCase("description"))
  52.             sitesList.setDescription(currentValue);
  53.         else if (localName.equalsIgnoreCase("pubdate"))
  54.             sitesList.setDate(currentValue);
  55.     }
  56.  
  57.     /** Called to get tag characters ( ex:- <name>AndroidPeople</name>
  58.      * -- to get AndroidPeople Character ) */
  59.     @Override
  60.     public void characters(char[] ch, int start, int length)
  61.             throws SAXException {
  62.  
  63.         if (currentElement) {
  64.             currentValue = new String(ch, start, length);
  65.             currentElement = false;
  66.         }
  67.  
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement