Soru & Cevap

XML'den Veri Çekme RSS İle ...

10.01.2014 - 05:28

Merhaba, RSS okuyucu yaparken bir sorunla karşılaştım. XML'de;

[code]<enclosure url="<a href="http://media.chip.com.tr/images/thumb/128/2013123116565320346.jpg" length="6163" type="image/jpg"/>[/code]

kodunda url'den href linkini almam gerekiyor. Normalde;

[code]<title>YAZI</title>[/code]

şeklinde olunca yapabiliyorum ama üsttekinde okuyamıyorum.. Yardım edin lütfen...

220 Görüntülenme

2 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

Profile picture for user fkurt97
fkurt97
10.01.2014 - 05:32

Title kısmın aşağıdaki kod ile çekip arraylist'e aktarıyorum;

[code]public ArrayList<String> getDateFromXml(String strng)  {
 
 
        ArrayList<String> list=new ArrayList<String>();
 
        try {
 
 
            URL url=new URL(strng);
            DocumentBuilderFactory dFactory=DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder=dFactory.newDocumentBuilder();
 
 
            Document document=dBuilder.parse(new InputSource(url.openStream()));
            document.getDocumentElement().normalize();
 
            NodeList nodeListCountry=document.getElementsByTagName("item");
            for (int i = 0; i < nodeListCountry.getLength(); i++) {
                Node node=nodeListCountry.item(i);
                Element elementMain=(Element) node;
 
 
                NodeList nodeListText=elementMain.getElementsByTagName("title");
                Element elementText=(Element) nodeListText.item(0);
 
                list.add(elementText.getChildNodes().item(0).getNodeValue());
 
 
 
            }
 
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
 
 
        return list;
    }[/code]

Profile picture for user fkurt97
fkurt97
10.01.2014 - 05:30

Title kısmın aşağıdaki kod ile çekip arraylist'e aktarıyorum;

[code]

      public ArrayList<String> getDateFromXml(String strng) {     ArrayList<String> list=new ArrayList<String>();   try {     URL url=new URL(strng); DocumentBuilderFactory dFactory=DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder=dFactory.newDocumentBuilder();     Document document=dBuilder.parse(new InputSource(url.openStream())); document.getDocumentElement().normalize();   NodeList nodeListCountry=document.getElementsByTagName("item"); for (int i = 0; i < nodeListCountry.getLength(); i++) { Node node=nodeListCountry.item(i); Element elementMain=(Element) node;     NodeList nodeListText=elementMain.getElementsByTagName("title"); Element elementText=(Element) nodeListText.item(0);   list.add(elementText.getChildNodes().item(0).getNodeValue());       }   } catch (MalformedURLException e) { e.printStackTrace(); }catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }       return list; }    

[/code]

Furkan KURT
10.01.2014 - 05:31
Pardon, kodlar karışık oldu.. yeni cevapta düzgün..