XML Parsing 2 ways, one works, one doesn't android

jonn

New Member
So, my issue is this:I am working with XML files, some that are in my bin folder in the application itself and some that are stored on the sd card because they are user generated. I am using the same code for parsing both, but when I am parsing from the sd card, it gives me errors, but not from the other one. Here is the code I am using for each:Getting file from bin:\[code\]XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setValidating(false); XmlPullParser myxml = context.getApplicationContext().getResources().getXml(data);\[/code\]and from sd:\[code\]XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setValidating(false); XmlPullParser myxml = factory.newPullParser(); File file = new File(Environment.getExternalStorageDirectory()+"/Platformer/level12.xml"); FileInputStream fis = new FileInputStream(file); myxml.setInput(new InputStreamReader(fis));\[/code\]Everything else is the same, which I will show below:\[code\]int eventType = myxml.getEventType(); String currentTag = ""; while(eventType != XmlPullParser.END_DOCUMENT) { if(eventType == XmlPullParser.START_TAG) { currentTag = myxml.getName(); } else if(eventType == XmlPullParser.TEXT) { if(currentTag.equalsIgnoreCase("height")) { height = Integer.parseInt(myxml.getText()); } else if(currentTag.equalsIgnoreCase("width")) { width = Integer.parseInt(myxml.getText()); } else if(currentTag.equalsIgnoreCase("level")) { levelData = http://stackoverflow.com/questions/10378687/myxml.getText(); levelData = levelData.replace("\n", ""); } else if(currentTag.equalsIgnoreCase("water")) { waterData = http://stackoverflow.com/questions/10378687/myxml.getText(); waterData = waterData.replace("\n", ""); } } eventType = myxml.next(); }\[/code\]So, I am not sure why, but when it gets to height part, it tells me it isn't an int, and when I print what is being checked, it shows a line break that it is attempting to parsed as an int. Is this due to the way the xml is being read in? And is there any way I can fix this? Thanks, and if you need anything else I will post it.Will
 
Back
Top