Can anyone point me to a explanation for or explain to me how I can easily parse the XML and get values of a w3c.Document on Android using only Android OS Libs?
I tried to use a implementation of dom4j, but it is very slow 🙁
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should definitively use the SAX APIs provided. Android XML parse API stacks on top of the normal java SAX one so in my opinion I would just use the normal Java SAX API and this way you get the ability to test your code as normal java desktop project.
XML parsing is always slow and using these SAX parsers is as good as it gets (unless you write a custom parser from the scratch).
Word of advice: Try to minimize string comparison and try to use hashmaps instead of long chains of if (token.isEqual(CONSTANT_TOKEN));.
Here are a few examples of Java XML parsing: http://java.sun.com/developer/codesamples/xml.html#sax
Android XML API is declarative, the paradigm is a bit different so in case you decide going with that, be prepared to read a few examples to learn its ways.
Finally, maybe 2 months ago I saw a chart benchmarking DOM vs SAX vs Android XML API (I can’t quite find the link now). The conclusion was that DOM was by far the slowest and SAX was top but not by a huge margin over Android’s XML implementation.