来自博客的RSS链接不起作用

时间:2013-11-01 23:07:02

标签: android jsoup

我正在按照本教程http://techiedreams.com/android-simple-rss-reader/开发一个rss阅读器应用程序。但是,当我把博客RSS链接(像这个http://blogname.com.br/feeds/posts/default?alt=rss)时,它不起作用。与此格式的其他链接www.site.com/index.php?format=feed&type=rss完美无瑕。哪个可能是问题? Bellow跟随解析器类。

public class DOMParser {

private RSSFeed feed = new RSSFeed();

public RSSFeed parseXML(String xml) {
    URL url = null;
    try {
        url = new URL(xml);
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    }

    try {
        //Criar as instâncias necessárias
        DocumentBuilderFactory dbf;
        dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();

        //Passa o xml
        Document doc = db.parse(new InputSource(url.openStream()));
        doc.getDocumentElement().normalize();

        //Pega todas as tags
        NodeList nl = doc.getElementsByTagName("item");
        int length = nl.getLength();

        for (int i = 0; i < length; i++) {
            Node currentNode = nl.item(i);
            RSSItem item = new RSSItem();

            NodeList nchild = currentNode.getChildNodes();
            int clength = nchild.getLength();

            //Pegar os elementos requeridos de cada item
            for (int j = 1; j < clength; j = j + 2) {

                Node thisNode = nchild.item(j);
                String theString = null;
                String nodeName = thisNode.getNodeName();

                theString = nchild.item(j).getFirstChild().getNodeValue();

                if (theString != null) {
                    if ("title".equals(nodeName)) {
                        // O valor do nó é "title", então devemos "setar"
                        // o valor do titulo de RSSItem
                        item.setTitle(theString);
                    } else if ("description".equals(nodeName)) {
                        item.setDescription(theString);                         
                        //Passa a descrição html para getar a url da imagem

                        String html = theString;
                        org.jsoup.nodes.Document docHtml = Jsoup
                                .parse(html);
                        Elements imgEle = docHtml.select("img");
                        item.setImage(imgEle.attr("src"));


                    } else if ("pubDate".equals(nodeName)) {
                        // We replace the plus and zero's in the date with
                        // empty string
                        String formatedDate = theString.replace(" +0000","");
                        item.setDate(formatedDate);
                    }
                }                   
            }
            //adiciona elemento a lista
            feed.addItem(item);
        }


    } catch (Exception e) {

    }
    //Retorna um objeto de RSSFeed, depois que todos os elementos foram adicionados a lista
    return feed;
}

}

非常感谢,非常糟糕的英语对不起。

1 个答案:

答案 0 :(得分:0)

我认为你混淆了博客网址。

 Unkown host: blogname.com.br