Unmarshalling XML files into Java objects in Android?

Question!

I'm making use of an API on the internet that is marshalling objects to XML files. Given that the XSD files are also available I'd like to be able to unmarshall them back in to Java objects once I've downloaded the files.

After looking around it looks like JAXB is the default library for doing this in Java, but as I'm developing a mobile app the extra 8.6MB dependency just isn't acceptable. I also found XStream, but it still weighs in at 7.9MB.

Poking around the Android SDK it looks like the only real XML parser available is SAX.

So here's the question:

  1. Is there a way to get SAX to do what I want?
  2. Is there another tool in the Android SDK that I've missed?
  3. Is there another library (that's significantly smaller) that will do this?

Thanks.



Answers

In Android SDK, besides SAX, DOM parser and XMLPullParser are also available.

If you don't want to build in-memory data structure completely by yourself, DOM might ease your pain - as long as the speed and memory footprint are the price you are willing to pay.



We have a product called XBinder that generates classes and encode/decode code from XSD. Version 2.1 takes up about 187K. Version 2.2 (due out in October 2010) takes about 101K (and is somewhat easier to use with Android than v2.1). Check it out here.

By : Kevin


kxml2-2.2.2 is a nice little lib (43K) which works on JavaME, does pull parsing and I've used it successfully. The only dependency it has is xmlpull, which is 8k. How's that for small?

Caveat is that it does not do any binding magic.

By : hoserdude


This video can help you solving your question :)
By: admin