Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives for DOM API on Android?

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

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

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

It's 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 quite essential to me.

like image 681
Kees Kist Avatar asked Nov 14 '22 19:11

Kees Kist


1 Answers

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

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

like image 191
hackbod Avatar answered Dec 11 '22 18:12

hackbod