开发者

Alternatives for DOM API on Android?

开发者 https://www.devze.com 2023-03-22 18:15 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消