Hey guys, A few months ago a conversation on this list about 'easy xml parsing on Android' got me working on a problem that I had been poking at for a few months resulting in a really simple library for XML parsing on any Java platform, including Android and I wanted to share it here for anyone else parsing up XML.
It is a tiny (4 class) abstraction layer that sits on top of any XML pull parser (like the one provided by android) and gives you the speed and low memory usage of pull parsing with the ease of XPath-like paths to match in a doc. Everything is released under an Apache 2 license: https://github.com/thebuzzmedia/simple-java-xml-parser SJXP is actually the result of many months of working on varying feed parsers in Java and slowly architecting simpler and simpler abstractions to the problem; it wasn't just a weekend hack-a-thon result or anything like that. A quick example of parsing story links from an RSS feed would look like this: ==== IRule linkRule = new DefaultRule(Type.CHARACTER, "/rss/channel/item/ link") { @Override public void handleParsedCharacters(XMLParser parser, String text) { // Also store the link, or something equivalently fancy } } XMLParser parser = new XMLParser(linkRule); parser.parse(...); ==== That's it, your callback gets triggered when the path matches and you're off to the races. No exception handlers, while-loops, event- switches, internal parser state handling etc. Namespaces for elements and attributes are both supported using bracket notation with the namespace URI. A quick example, if you wanted to parse the standard dublin core <dc:subject> element, would be defined as: ==== /rss/channel/[http://purl.org/dc/elements/1.1/]subject ==== All the source is Javadoc'ed up to a fault if you want to look at the API. Performance and memory usage is right on par with straight XML pull parsing without any of the headache. I have benchmarks for tiny files up to 10MB monster XML files up on the project page as well as more examples and project information if you are interested http://www.thebuzzmedia.com/software/simple-java-xml-parser-sjxp/ For Android you can just drop the single SJXP.jar into your project and you're all done, no other dependencies. I wasn't looking to write my own parser (I would rather die) I just wanted to make using the existing one ease as pie with little to no extra overhead and I think a lot of folks parsing XML might find this approach handy. In the examples above I used RSS/feeds as examples, but it doesn't care. I just figured that was a common use case. You can parse anything in a markup format that org.xmlpull will eat. Feedback, comments and recommendations are all appreciated. Please phrase any and all ridicule in the form of unbounded praise. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

