Hi everyone, I am a beginner of android programming, these several weeks I am trying to write a RSS reader. As I said, I use SAX to retrieve the elements from xml of a website. All other elements I can retrieve except the content inside the <content:encoded>.
Below is my Handler.java can anyone help me? thz so much~~~ ______________________________________________________________________________ package first.user_ss; import java.util.ArrayList; import java.util.List; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; public class MyHandler extends DefaultHandler{ private boolean in_item = false; private boolean in_title = false; private boolean in_link = false; private boolean in_desc = false; private boolean in_date = false; private boolean in_contentencoded =false; //it is added by myself private boolean in_cate=false; private boolean in_mainTitle = false; private List<News> li; private News news; private String title=""; private StringBuffer buf=new StringBuffer(); public List<News> getParsedData() { return li; } public String getRssTitle() { return title; } @Override public void startDocument() throws SAXException { li = new ArrayList<News>(); } @Override public void endDocument() throws SAXException { } @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { if (localName.equals("item")) { this.in_item = true; news=new News(); } else if (localName.equals("title")) { if(this.in_item) { this.in_title = true; } else { this.in_mainTitle = true; } } else if (localName.equals("link")) { if(this.in_item) { this.in_link = true; } } else if (localName.equals("description")) { if(this.in_item) { this.in_desc = true; } } else if (localName.equals("pubDate")) { if(this.in_item) { this.in_date = true; } } else if (localName.equals("content:encoded")) { if(this.in_item) { this.in_contentencoded = true; } } else if (localName.equals("category")) { if(this.in_item) { this.in_cate = true; } } } @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (localName.equals("item")) { this.in_item = false; li.add(news); } else if (localName.equals("title")) { if(this.in_item) { news.setTitle(buf.toString().trim()); buf.setLength(0); this.in_title = false; } else { title=buf.toString().trim(); buf.setLength(0); this.in_mainTitle = false; } } else if (localName.equals("link")) { if(this.in_item) { news.setLink(buf.toString().trim()); buf.setLength(0); this.in_link = false; } } else if (localName.equals("description")) { if(in_item) { news.setDesc(buf.toString().trim()); buf.setLength(0); this.in_desc = false; } } else if (localName.equals("pubDate")) { if(in_item) { news.setDate(buf.toString().trim()); buf.setLength(0); this.in_date = false; } } else if (localName.equals("content:encoded")) { if(this.in_item) { news.setCon(buf.toString().trim()); buf.setLength(0); this.in_contentencoded = false; } } else if (localName.equals("category")) { if(in_item) { news.setCate(buf.toString().trim()); buf.setLength(0); this.in_cate = false; } } } @Override public void characters(char ch[], int start, int length) { if(this.in_item||this.in_mainTitle) { buf.append(ch,start,length); } } } -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en