2

I have xml file this format from sd card.

<consignments creationDate="2015-05-11 08:04:38">
 <consignment iid="142435846">
  <consignmentId>194556772</consignmentId>
  <orderCode>MUC-EC-4556772</orderCode>
  <pickupDate>2015-04-01</pickupDate>
  <referenceConsignor>236847.1</referenceConsignor>
  <consignorCountry>DE</consignorCountry>
  <consignorZip>83125</consignorZip>
  <consignorCity>EGGSTAETT</consignorCity>

</consignment>

how to read this xml file from sd card and show result all items into textview?

Shwe Min
  • 15
  • 3
  • What problem you are facing to parse it? – Manish May 13 '15 at 04:08
  • please try by your own first,if you are facing problem in result than ask for help. – Jignesh Jain May 13 '15 at 04:11
  • check this link https://diptimayapatra.wordpress.com/2013/07/05/xamarin-reading-xml-file-from-sd-card-in-android/ – Jignesh Jain May 13 '15 at 04:12
  • you comment answer for eclipse DDMS Tool .i using eclipse ADT tool for java I'm looking answer from the same link (http://stackoverflow.com/questions/15967896/how-to-parse-xml-file-from-sdcard-in-android) but not so okay for my xml format. – Shwe Min May 13 '15 at 04:48

2 Answers2

1

like this you can parse.

 try {
     File file = new File("mnt/sdcard/xxx.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("consignment");
     Node node = nodeList.item(0);
     Element fstElmnt = (Element) node;
     String id=fstElmnt.getAttribute("iid");
     String consignmentId=(String)fstElmnt.Element("consignmentId");
     String orderCode=(String)fstElmnt.Element("orderCode");

    }
    catch (Exception e) 
    {
     System.out.println("XML Pasing Excpetion = " + e);
    }
Ram
  • 1,408
  • 13
  • 29
0

To pass your file in to be read you will need to do first get your file:

String sdcardDir = Environment.getExternalStorageDirectory().getAbsolutePath;
File fileToRead = new File(dir, "path/to/file");
InputStream stream = new FileInputStream(fileToRead);

See the following site on how to parse XML: http://developer.android.com/training/basics/network-ops/xml.html

With the inputstream you can now pass it to your parser from the link.

EDIT: You can add it to your textview by adding it to your layout then in your activity/fragment find the view and call .setText(String).

asu
  • 1
  • 2