Is there an easier way to parse XML in Java?

Tags: java xml android

I'm trying to figure out how to parse some XML (for an Android app), and it seems pretty ridiculous how difficult it is to do in Java. It seems like it requires creating an XML handler which has various callbacks (startElement, endElement, and so on), and you have to then take care of changing all this data into objects. Something like this tutorial.

All I really need is to change an XML document into a multidimensional array, and even better would be to have some sort of Hpricot processor. Is there any way to do this, or do I really have to write all the extra code in the example above?

There are two different types of processors for XML in Java (3 actually, but one is weird). What you have is a SAX parser and what you want is a DOM parser. Take a look at for how to use the DOM parser. DOM will create a tree which you can navigate pretty easily. SAX is best for large documents but DOM is much easier if slower and much more memory intensive.

By : stimms

Check this article for ways to handle XML on Android. Maybe the DOM or XML Pull style fit your style better

Working with XML on Android

By : jitter

Try, its an XML to Java serialization and binding framework, its fully compatible with Android and is very lightweight, 270K and no dependencies.

By : ng.

This video can help you solving your question :)
By: admin