如何从中获取特定的XML数据?

时间:2014-06-17 02:39:41

标签: android

我正在尝试从sdcard的XML文件中获取值。 我不知道我在图片中看到了这个值。

请帮帮我。谢谢!

xml view

2 个答案:

答案 0 :(得分:1)

尝试以下代码: -

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);
     }

见以下链接: -

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/

答案 1 :(得分:0)

您可以从以下代码中读取外部文件:

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

之后,您可以使用android中提供的XMLParser来获取所需的数据。完成Parsing XML Data