I'm parsing large XML files (~1-2M) in my application. Occasionally parser fails
when parsing some files.
Symptoms:
Sometimes the same file is parsed successfully, sometimes - not.
If parsing of a file fails it will take some time before the file can be parsed
successfully again.
I use 2 types of XML parsers: SAX (XMLReader) and Pull (XMLPullParser),
both of them fail near the same place in the file.
I use FileInputStream as the input source for parsers.
The same file compressed via zip and then opened via ZipFile.getInputStream
(almost) always parsed successfully.
I tryed to wrap FileInputStream with BufferedInputStream - nothing changed.
If parsing fails the next attempts to parse the file fail in the same place in the file.
I believe there can be two causes:
FileInputStream works incorrectly.
XML parsers work incorrectly with FileInputStream's (I heard both parsers
implemented on the same base in Android).
Please help to fix the problem or advise a workaround.
Thanks.
This is the case if you experience the problem only sometimes. If the problem occurs each time you run the application the problem could be with XML.
In my case I believe it is device (I have Samsung I5700) or sdcard issue, because none of my application's users report same problem.
I'm going to reformat sdcard with android or try/buy another one.
Related
I am having some difficulties with my android app parsing an xml that contains links to PDF files. It should open a listView showing all of the files listed in the xml. However, most of the time it just freezes up on me. The app was made by a developer no longer with us, and all I have is the apk and not the source files. Is there a way to use the apk to get the source files and figure out what the issue is? Android is not my forte and I'm at a loss with how to fix this.
UPDATE:
It appears that devices running 2.2 display all the songs just fine, while the newer versions of Android crash when ran.
I've had problems with android 2.2 on my HTC desire taking a long time to parse large XML files. There wasn't much I could do other than switch from DOM to SAX which for some reason was a lot quicker
However debugging this without source code is likely to be pretty difficult. Not least because fixing the issue when and if you find it will require you to re-compile a new class in replacement for the one which keeps freezing.
I would suggest you look into decompiling the APK back into source code.
According to Wikipedia APK files are based on the Jar file format which in turn is a Zip file:
http://en.wikipedia.org/wiki/APK_%28file_format%29
That makes this task a little easier as you won't need to look for a decompiler that is specific to android but a more generic Java Decompiler.
A quick search on google suggests this one:
http://java.decompiler.free.fr/
If you can decompile the app back to source code and then get that source code into eclipse and rebulild from source then you can start to debug.
I made an Android Applicatiob to upload videos to my server, it's working fine but if the file bigger than 21MB it's forced close.
so i think it's a memory issue, i tried to use setFixedLengthStreamingMode method
conn.setFixedLengthStreamingMode((int) new File(existingFileName).length());
but it's not working at all with the small & big files.
I passed the value to the Log to make sure it the file size in bytes and that is correct but the method not working
I tried to convert the connection to chunk mode by using this line
conn.setChunkedStreamingMode(100);
but also this line makes the Application fails
so I don't know what to do
Probably you are loading entire file into memory. This link may be helpful to cater your problem https://stackoverflow.com/a/9630475/830945
I have successfully implemented SaxParser in my application to parse XML files. My app works well with other online XML files, but not with a specific one. I opened this specific XML file on my browser than went to "page source", copied everything and pasted inside a local XML file in my project, and the parser worked.
When I try to parse this file from it's source on internet, on Logcat I get error message:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: syntax error
The only thing comes to my mind is, the source file's url is something like "example.com/showxml". So the url does not end with a .xml extension.
Can this be the cause of the error?
Thanks in advance!
Notes:
1. Internet permission is listed in my manifest.
2. I don't think there is a syntax error in the XML file, since it worked when I copy & paste it to a local file.
UPDATE:
I uploaded the XML file to another website, in order to try if I can reach it from there. And it worked. Seems like my problem is caused by the domain that I am trying to get the original file from.
dump the file inside android, perhaps your code is using the wrong char encoding, bad bof etc.
Unfortunately, there was a huge mistake by me. The file was not an XML file, it was JSON. But somehow, Firefox was showing it in XML format, and giving me huge confusion. I guess the URL I was calling was some kind of a webservice which is able to return the data both in XML and JSON formats. Anyway, problem solved. Thanks to everyone who spend a minute here.
I am using plist as data for my android application since the iphone also supports the same.
I have written a parser which parsers character by character, but it takes a really long time to run my app. I think a sax parser would solve this, do you have any suggestions?
Also I have this link which says its a sax based parser for plist android but i cant figure out a way to run this in eclipse if any one knows please help out.
Thanks
Deepesh
I am working with this app right now.
Everything is straight forward. Download this
https://github.com/CarlLee/android-plist-parser/downloads
There are 2 projects there
android-plist-parser-app - objects and parsing logic
android-plist-parser-test - testing app.
Start to discover from testing app and you will find out how it works.
I want to load a single XML file of 1.2Mb in android through assets folder as raw file. I heard that there is a limitation in android of 1Mb for a single xml file. How can I get rid of it? Is there any option to overcome this issue?
First, don't use assets/ for XML, if your intention is to use it in your application. Use res/xml/, as parsing will be about ten times faster, and will also take up less space.
Then, I would simply try it with your file and see if it blows up. I know there is a limit, but I do not know what the threshold size is.
If it blows up, you will either need to split it into multiple files (each with a subset of your data), or not package it with the application, instead downloading it from a server on first run of your appl.