I can not figure out how to implement the work of sax parser so that the pictures are also loaded into the tape.

Parser class:

package app.kray.anddev; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import android.sax.Element; import android.sax.EndElementListener; import android.sax.EndTextElementListener; import android.sax.RootElement; import android.util.Xml; public class NewParser { protected InputStream getInputStream() { URL feedUrl = null; try { feedUrl = new URL("http://anddev.ru/feed"); } catch (MalformedURLException e1) { feedUrl = null; } try { return feedUrl.openConnection().getInputStream(); } catch (IOException e) { return null; } } public ArrayList<PostItem> parse() { final PostItem currentPost = new PostItem(); final ArrayList<PostItem> messages = new ArrayList<PostItem>(); RootElement root = new RootElement("rss"); Element channel = root.getChild("channel"); Element item = channel.getChild("item"); item.setEndElementListener(new EndElementListener() { public void end() { messages.add(currentPost.copy()); } }); item.getChild("title").setEndTextElementListener( new EndTextElementListener() { public void end(String body) { currentPost.title = body; } }); item.getChild("link").setEndTextElementListener( new EndTextElementListener() { public void end(String body) { currentPost.link = body; } }); item.getChild("description").setEndTextElementListener( new EndTextElementListener() { public void end(String body) { currentPost.description = body; } }); item.getChild("pubDate").setEndTextElementListener( new EndTextElementListener() { public void end(String body) { currentPost.setDate(body); } }); try { Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler()); } catch (Exception e) { return null; } return messages; } } 

jasoup also jasoup to pull out links to pictures and load them into imageView , I have little experience in java, but I really want to figure it out. Thank you in advance.

    1 answer 1

    the first part - sax parser threshes all the XML, breaking up into records ( <item></item> )

    the second part - with the help of JSoup you parse the values, naked HTML, which SAX Parser compiles to you. JSoup can use strings and return structures.

    There are many examples on the official website.

    if you want complete comfort, you can also make JAXB turning each tape into a java-object (POJO):

    eg:

     class SiteItem: private String title; private String link; private String comments; ...