Hoi,
I'am building a RSS reader based on newsdroid and androidRSS.
(newsdroid: http://www.helloandroid.com/tutorials/newsdroid-rss-reader)
(androidRSS:
http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/index.html)
Up til now, i'am able to read a RSS-file and parse it. Although,
during parising, the parser never calls the startElement procedure !
Useless to say that this is a great problem for me ! Log-files during
processing shows parsing uses startDocument, endElement and Characters
without any problem. It just never reach startElement.
Anyone got a clue ?
This is my code:
##############
class RSSReader
##############
.... / ...
RSSHandler rh = new RSSHandler();
try {
rh.updateArticles(this, link);
} catch (Exception e) {
Log.i(TAG, e);
}
.... / ...
##############
class RSSHandler
##############
.... / ...
/** STARTDOCUMENT **/
public void startDocument() throws SAXException {
targetFlag = TARGET_FEED;
}
/** STARTELEMENT **/
public void startElement(String uri, String localName, String qName,
Attributes atts) throws
SAXException{
if(localName.trim().equals("title")) {
inTitle = true;
} else if (localName.trim().equals("item")){
targetFlag = TARGET_ARTICLES;
inItem = true;
} else if (localName.trim().equals("description")){
inDescription = true;
} else if (localName.trim().equals("pubDate")){
inPubdate = true;
} else if (localName.trim().equals("link")){
inLink = true;
}
}
/** ENDELEMENT **/
public void endElement(String uri, String name, String qName) throws
SAXException {
if(name.trim().equals("title")) {
inTitle = false;
} else if (name.trim().equals("item")){
targetFlag = TARGET_FEED;
inItem = false;
} else if (name.trim().equals("description")){
inDescription = false;
} else if (name.trim().equals("pubDate")){
inPubdate = false;
} else if (name.trim().equals("link")){
inLink = false;
}
if (targetFlag == TARGET_ARTICLES) {
rssDB.insertItem(feedId, currentArticle.title,
currentArticle.pubdate,
currentArticle.description,
currentArticle.link);
currentArticle.feedId = feedId;
currentArticle.title = null;
currentArticle.pubdate = null;
currentArticle.description = null;
currentArticle.link = null;
}
}
/** CHARACTERS **/
public void characters(char ch[], int start, int length) {
String chars = (new String(ch).substring(start,start+length));
if(inItem) {
if(inTitle) currentArticle.title = chars;
if(inPubdate) currentArticle.pubdate = chars;
if(inDescription) currentArticle.description =
chars;
if(inLink) currentArticle.link = chars;
}
}
/** GET ARTICLES **/
public void updateArticles(Context ctx, String link) throws
MalformedURLException {
URL url = new
URL("http://pipes.yahoo.com/hugozalm/a20popularblogs?
_render=rss");
try {
int targetFlag = 1;
A20DB db = new A20DB(ctx);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
InputSource is = new InputSource(url.openStream());
xr.parse(is);
} catch (IOException e) {
Log.e("A20RSS",e.toString());
} catch (SAXException e) {
Log.e("A20RSS",e.toString());
} catch (ParserConfigurationException e) {
Log.e("A20RSS",e.toString());
}
}
.... / ...
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en