3

what I'm doing wrong?

InputStream in = new FileInputStream("/sdcard/new.xml");
XmlPullParser parser1 = Xml.newPullParser();
parser1.setInput(in, "utf-8");

ok. try parsing each tag of xml code

while (parser1.getEventType()!= XmlPullParser.END_DOCUMENT) {

Toast.makeText(this, parser1.getName(),Toast.LENGTH_SHORT).show();
parser1.nextToken();}

error :(

androidGuy
  • 5,553
  • 12
  • 39
  • 56
yuriy
  • 264
  • 1
  • 3
  • 11
  • runtime error? compiler error? exception? output not as you expected? Please do not put us into guess game. Put more details – Sarwar Erfan Dec 13 '11 at 11:49
  • Runtime error. With data initialization as XmlPullParser parser = getResources().getXml(R.xml.new) was all ok. – yuriy Dec 13 '11 at 11:53
  • is your sdcard mount dir ok? is there really new.xml? have you added permission in manifest for accessing external storage? – Sarwar Erfan Dec 13 '11 at 11:58
  • Yes, the file exists, the same program successfully writes to disk. or to read something want? – yuriy Dec 13 '11 at 12:02
  • read the file into a buffer string, parses it. all ok – yuriy Dec 13 '11 at 13:01
  • Have a look at [this answer](http://stackoverflow.com/questions/6079637/xmlpullparser-how-to-attain-res-raw-xml-xmlfilename/6079787#6079787) by hackbod. – kaneda Nov 27 '12 at 03:07

1 Answers1

1

So, it works (exception handling is not shown):

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
File file = new File(Environment.getExternalStorageDirectory()+ "/new.xml");
FileInputStream fis = new FileInputStream(file);
parser.setInput(new InputStreamReader(fis));
yuriy
  • 264
  • 1
  • 3
  • 11