XML解析新闻应用程序

时间:2015-04-06 09:39:13

标签: android eclipse sdk

我已经为拼贴项目的xml解析创建了新闻应用程序rss feed 这是xml http://goo.gl/X8tIr1所以任何人都指导我构建该应用程序或提供代码来帮助拼贴项目

任何人都可以给我整个代码

2 个答案:

答案 0 :(得分:1)

浏览Creating-a-simple-rss-application-in-android。这应该可以帮到你。

答案 1 :(得分:0)

我告诉您如何在doInBackground中使用XML PArsing。试试这样:

        DOMParser dParser = new DOMParser();
        String abc = dParser.getXmlFromUrl(params[0]);
        Document doc = dParser.getDocElement(abc);
        NodeList n1 = doc.getElementsByTagName("channel");

        for (int i = 0; i < n1.getLength(); i++) {
            Element e = (Element) n1.item(i);
            NodeList nl1 = e.getElementsByTagName("item");

            for (int j = 0; j < nl1.getLength(); j++) {
                Element e1 = (Element) nl1.item(j);
                NodeList ntitle = e1.getElementsByTagName(TITLE);
                NodeList ndate = e1.getElementsByTagName(PUBDATE);
                NodeList ndesc = e1.getElementsByTagName(DESCRIPTION);

                for (int k = 0; k < n1.getLength(); k++) {
                    Element e2 = (Element) ntitle.item(k);
                    Element e3 = (Element) ndate.item(k);
                    Element e4 = (Element) ndesc.item(k);

                    Pojo pojo = new Pojo();
                    pojo.setTitle(getCharacterDataFromElement(e2));
                    pojo.setPubdate(getCharacterDataFromElement(e3));
                    pojo.setDescription(getCharacterDataFromElement(e4));
                    itemList.add(pojo);
                }
            }
        }

        return null;