如何在媒体上解码xml dom解析:thumbnail标签

时间:2016-10-07 13:35:28

标签: android xml

tag

如何在媒体上解码xml dom解析:thumbnail标签 这是我的xml链接:http://indianexpress.com/section/sports/feed/

1 个答案:

答案 0 :(得分:2)

try
            {
                XMLParser xmlParser = new XMLParser();
                //result string is xml result
                Document document = xmlParser.getDomElement(result);
                NodeList nodeList = document.getElementsByTagName("item");

                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Element element = (Element) nodeList.item(i);
                    String title = xmlParser.getValue(element, "title");
                    String link = xmlParser.getValue(element, "link");
                    String pubdate = xmlParser.getValue(element, "pubDate");
                    NodeList media = element.getElementsByTagName("media:thumbnail");
                    Element elementMedia = (Element) media.item(0);
                    String url = elementMedia.getAttribute("url");

                    utils = new DataUtils();
                    utils.setProductName(title);
                    utils.setProductDate(pubdate);
                    utils.setProductDesc(link);
                    utils.setProductImage(url);
                    dataList.add(utils);
                }