views:

73

answers:

2

I am looking for an XML parsing solution for Android besides the built-in kXML pull parser. I am trying to parse a large (4MB+) XML file downloaded from a server and the kXML parser throws an OutOfMemory error after trying to allocate a 1MB+ byte array while parsing. A good streaming XML parser shouldn't be allocating such a big array!!

The kXML v2 parser being used in Android appears to be about 7 years old. I'd like to try something else to see if it fixes my problem, ideally something that implements the same org.xmlpull.v1 interface since my code is already written against it. Woodstox looks like a good choice and it has an XMLPullParser adapter but apparently the Android engineers are making it difficult to include the javax.xml.streaming libraries. I see some rather involved "jar-jar" workarounds but I'd rather not spend a bunch of time messing around with Ant if there is an easier way. Has anyone else already gotten another XML pull parser working and can point me to it?

+1  A: 

In a worst case scenario, you might revert to SAX which is the most memory efficient approach. Though it is a big change in your code I guess.

spa
A: 

The best solution I've found so far is an old Javolution library that contains an XmlPullParser. The Javolution pull parser doesn't actually implement org.xmlpull.v1.XmlPullParser but it has the exact method signatures except that its methods return CharSequence instead of String. This was easily remedied by wrapping it into a homemade adapter.

Unfortunately it seems that the Javolution pull parser has been deprecated and cannot be found in recent versions of the JAR but I found an older JAR file that still has it here: http://download.osgeo.org/webdav/geotools/org/javolution/javolution/3.7.1/

Also it turns out my problem was that the XML file happened to contain over 1MB of 0x00 chars at the end of it, which are not legal characters in the first place!! However if anyone wants to try another parser I hope this helps you.

satur9nine