user3517970
user3517970

Reputation: 63

How to get specific XML data from this?

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

Upvotes: 0

Views: 272

Answers (2)

duggu
duggu

Reputation: 38439

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/

Upvotes: 1

dchks11
dchks11

Reputation: 695

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

Upvotes: 0

Related Questions