As far as I understand there are three major ways of parsing XML:
- SAX
- DOM
- XmlPullParser
Wrong! Neither of those is the best way. What you really want is annotation based parsing using the Simple XML Framework. To see why follow this logic:
- Java works with objects.
- XML can be represented using Java objects. (see JAXB)
- Annotations could be used to map that XML to your Java objects and vice versa.
- The Simple XML Framework uses Annotations to allow you to map your Java and XML together.
- Simple XML is capable of running on Android (unlike JAXB).
- You should use Simple XML for all of your XML needs on Android.
And to help you do exactly that I will point you to my own blog post that explains exactly how to use the Simple library on Android.
Unless you have a 100MB XML file then Simple will be more than fast enough for you. It is for me, I use it on all of my Android XML projects.
N.B. I should point out that if you require the user to download XML files that are more than 1MB on Android then you may want to rethink your strategy. You might be doing it wrong.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…