0

I am trying to get a value from an XML file from sdcard. I have no idea to get this value I figured in the picture.

Please help me. Thank you !

xml view

user3517970
  • 63
  • 2
  • 10

2 Answers2

1

try below code:-

try {
         File file = new File("mnt/sdcard/Backup_Apps/call_logs/calllog_35777569.xml");
         InputStream is = new FileInputStream(file.getPath());
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         DocumentBuilder db = dbf.newDocumentBuilder();
         Document doc = db.parse(new InputSource(is));
         doc.getDocumentElement().normalize();

         NodeList nodeList = doc.getElementsByTagName("map");

         for (int i = 0; i < nodeList.getLength(); i++) {

             Node node = nodeList.item(i);

             Element fstElmnt = (Element) node;

             System.out.println(fstElmnt.getAttribute("pwd"));

         }

     } catch (Exception e) {
         System.out.println("XML Pasing Excpetion = " + e);
     }

see below link:-

how to parse xml file from Sdcard in Android

http://diptimayapatra.wordpress.com/2013/07/05/xamarin-reading-xml-file-from-sd-card-in-android/

Community
  • 1
  • 1
duggu
  • 37,851
  • 12
  • 116
  • 113
  • Hi . . Your answer helps me a lot. It nearly makes me perfect. But I think your code to finding "pwd" not working enough. It can't show me anything. But a.xml is successfully loaded by yours. I also added externalstorage read permission to manifest. But it can't still work. If you don't mind , Could I make send my code (Really a little) to you with a.xml. Thank you so much for Helping me. – user3517970 Jun 18 '14 at 04:01
  • I have thank you a lot! My problem is fixed by your answer. I only needed to change a bit of code. NodeList nodeList = doc.getElementsByTagName("string"); System.out.println(fstElmnt.getTextContent()); Thank you so so much ! :) – user3517970 Jun 19 '14 at 03:41
0

You can read the external file from below code :

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");

And after that you can use XMLParser available in android to get the required data. Go through Parsing XML Data

aksdch11
  • 683
  • 6
  • 14
  • I am new to android programming. Could you please make some code to get the required data to my textview1 ? – user3517970 Jun 17 '14 at 02:50
  • I will suggest that you go through these tutorials they are very useful for beginners and it covers all basics : http://www.mkyong.com/tutorials/android-tutorial/ – aksdch11 Jun 17 '14 at 02:53