2016-10-07 63 views

回答

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); 
       }