Alternatives to the DOM API on Android?

We have an internal library that uses the org.w3c.dom API to read and write XML. When I tried to use this library on Android, I found that it no longer works. It seems that Android only implements a subset of the DOM API. I don’t know the reasons for this, and I know that it is fixed in Android 2.2, but I still need to focus on older devices.

I know several alternative DOM libraries for "regular" Java, such as XOM and Dom4j. Can anyone recommend a DOM library that meets the following goals?

  • It should work on Android.
  • It should be small (because people pay per MB).
  • Ideally, it should look like the org.w3c.dom API, since I need to rewrite the existing code.

It is probably impossible to meet all three goals, but with two I would already be happy. Also, out of curiosity, does anyone know why the DOM API is not fully supported? I can understand the reasons for not implementing Java Sound, etc., but XML seems very important to me.

+5
source share
1 answer

My general recommendation would be to stay away from the DOM parser, as performance is terrible compared to using a direct parser. You will be much better off with XmlPullParser or SAX.

I know you already have code that uses the DOM, and that is how you want to do it. But believe me, you should not use this on a mobile device.

+1
source

All Articles