Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any StAX implementation for android?

I want to use StAX API implementation in android 1.6 and above devices. Are there any implementations out there ? I cannot use the jar file directly since it gives issues regarding inner class. If its not available, is there any way I can recompile the implementation ? Is there an alternate way for POJO class to be mapped into XML and vice versa directly, please exclude SAX parser and DOM parser.

I think it is possible for POJO class to be mapped into XML and vice versa using JAXB. But the situation is like this. Consider this example,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cars>
<car registration="abc123">
    <brand>BMW</brand>
    <description>Sedan</description>
</car>
<car registration="abc123">
    <brand>Ferrari</brand>
    <description>SportsCar</description>
</car>
</cars>

Now in the result I want List which has the 2 cars in it.

Also how does JAXB parser fare against StAX ?

like image 397
Prabhat Avatar asked Apr 21 '11 00:04

Prabhat


2 Answers

As far as I know, both Woodstox and Aalto should work on Android. Aalto is the single fastest conforming XML parser on Java platform, if that matters; and Woodstox supports widest range of XML constructs (from full DTD handling to RelaxNG/XML Schema validation).

For binding POJOs to XML, you could also consider Jackson extension jackson-xml-databind: while Jackson is mainly JSON processor, extension supports JAXB-style data binding for XML. And does it faster than JAXB reference implementation (see jvm-serializers benchmark). This also should work on Android (Jackson itself is nr 1 JSON parser on Android).

like image 109
StaxMan Avatar answered Sep 26 '22 01:09

StaxMan


So what you really want to "map POJOs into the XML and vice versa" is the Simple XML Library. You can use it with every version of Android from 1.5 up.

I even wrote a blog post explaining how to include it in one of your projects.

like image 40
Robert Massaioli Avatar answered Sep 22 '22 01:09

Robert Massaioli