AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Android XML file einlesen

Ein Thema von Cylence · begonnen am 25. Apr 2012 · letzter Beitrag vom 25. Apr 2012
 
Benutzerbild von Cylence
Cylence

Registriert seit: 2. Sep 2004
Ort: Allgäu
246 Beiträge
 
Delphi 7 Enterprise
 
#2

AW: Android XML file einlesen

  Alt 25. Apr 2012, 11:41
Ich habs endlich: so gehts:

Delphi-Quellcode:
   public static void parse(){
   URL url;
   try {
      url = new URL("http://www.tastekid.com/ask/ws?q=" + MRUtils.mSimiliarTitle + "&verbose"); 
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();   
      if (conn.getResponseCode() == HttpURLConnection.HTTP_OK){         
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              DocumentBuilder db = dbf.newDocumentBuilder();
              Document doc;
              doc = db.parse(url.openStream());
              doc.getDocumentElement().normalize();                             
              NodeList XResultLst = doc.getElementsByTagName("similar");             
              Node XResultitem = XResultLst.item(0);
              NodeList ResultLst = ((Element) XResultitem).getElementsByTagName("results");
              Node Resultitem = ResultLst.item(0);
              NodeList itemLst = ((Element) Resultitem).getElementsByTagName("resource"); 
              Integer ResultsCount = itemLst.getLength();
              Similiararrays.SimName = new String[ResultsCount];
              Similiararrays.SimType = new String[ResultsCount];
              Similiararrays.SimDescription = new String[ResultsCount];
              Similiararrays.SimWikiURL = new String[ResultsCount]; 
              Similiararrays.SimSampleTitle = new String[ResultsCount];
              Similiararrays.SimSampleURL = new String[ResultsCount];   
              for(int i=0; i < ResultsCount; i++){
                    Node item = itemLst.item(i);
                    if(item.getNodeType() == Node.ELEMENT_NODE){   
                          Element ielem = (Element)item;   
                          NodeList SimName = ielem.getElementsByTagName("name"); 
                          NodeList SimType = ielem.getElementsByTagName("type");
                          NodeList description = ielem.getElementsByTagName("wTeaser");
                          NodeList SimWikiURL = ielem.getElementsByTagName("wUrl"); 
                          NodeList SimSampleTitle = ielem.getElementsByTagName("yTitle"); 
                          NodeList SimSampleURL = ielem.getElementsByTagName("yUrl"); 
                          Similiararrays.SimName[i] = SimName.item(0).getChildNodes().item(0).getNodeValue();
                          Similiararrays.SimType[i] = SimType.item(0).getChildNodes().item(0).getNodeValue();
                          Similiararrays.SimDescription[i] = description.item(0).getChildNodes().item(0).getNodeValue();
                          Similiararrays.SimWikiURL[i] = SimWikiURL.item(0).getChildNodes().item(0).getNodeValue();   
                          Similiararrays.SimSampleTitle[i] =SimSampleTitle.item(0).getChildNodes().item(0).getNodeValue();
                          Similiararrays.SimSampleURL[i] = SimSampleURL.item(0).getChildNodes().item(0).getNodeValue();
                    }
                   
              }
        }      
   } catch (MalformedURLException e) {
      e.printStackTrace();
   }
 catch (DOMException e) {
      e.printStackTrace();
   }
 catch (IOException e) {
      e.printStackTrace();
   }
 catch (ParserConfigurationException e) {
      e.printStackTrace();
   }
 catch (SAXException e) {
      e.printStackTrace();
   }
   
   }
Tom
Just DO it
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:44 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz