frAydjwe Posted May 11, 2011 Share Posted May 11, 2011 Bonjour, Je souhaite lire un fichier config.XML qui est situé sur ma carte SD pour récupérer les informations que je souhaite pour mon application. Quelqu'un sait-il comment faire ?! Je vous remercie, j'en ai vraiment besoin ... ! Merci beaucoup ... ! Link to comment Share on other sites More sharing options...
frAydjwe Posted May 12, 2011 Author Share Posted May 12, 2011 Bonjour, Je souhaite lire un fichier config.XML qui est situé sur ma carte SD pour récupérer les informations que je souhaite pour mon application. Quelqu'un sait-il comment faire ?! Je vous remercie, j'en ai vraiment besoin ... ! Merci beaucoup ... ! Problème résolu : String xmlInSD = "/sdcard/config.xml"; try { File file = new File(xmlInSD); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(file); document.getDocumentElement().normalize(); NodeList node = document.getElementsByTagName("ressources"); Element entry = (Element) node.item(0); // prend le 1er nœud, en même temps y'en a qu'un Element eIp = (Element) entry.getElementsByTagName("ip").item(0); // là ya qu'une entrée ip par ressources Element ePort = (Element) entry.getElementsByTagName("port").item(0); // là ya qu'une entrée port par ressources ip = eIp.getFirstChild().getNodeValue(); port = ePort.getFirstChild().getNodeValue(); } catch (Exception e) { e.printStackTrace(); } } Voilà, pour ceux qui en auraient besoin. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.