简体   繁体   中英

Android and Google App Engine: supported XML Binding Tool available?

A REST XML (not JSON!) Web Service should exchange XML Schema specified XML between a Google App Engine and an Android app.

I wanted to use XStream for both, however, I could not get it to work for the Google App Engine, therefore to me Apache XMLBeans is the next best choice (JAXB does not work on both). However, with Google App Engine there is no problem, but on Android, I get several severe exceptions (eg. due to the usage of the Stax API with its javax.xml.* packages).

So,

  1. Is there any other XML-binding possibility to stream XML documents on GAE and Android?
  2. If not, is it possible to patch Apache XMLBeans to work with Android?

Thanks!

I'm poking in the dark here, since i haven't tried anything of this, yet:

There's this blog entry from XBinder which claims that they are releasing an android-compatible version "in a few weeks". While that might not be an option right now, they also explain a bit of how they have done it, wrapping a light StAX-like wrapper on the XmlPull support already present in Android.

(my answer originally had another paragraph on XStream working on android, but then i read the question again and saw that your problem was with getting XStream to work on the AppEngine side...)

An XML data binding framework that works on both Google App Engine and Android is Simple . It uses annotations similar to JAXB to annotate a POJO which can then be serialized and deserialized in XML. For example, an annotated object would look like.

@Root
public class Pojo {
   @Attribute
   private String name;
   @Element
   private String value

   public String getName() {
      return name;
   }

   public String getValue() {
      return value;
   }
}

Then to generate XML all you have to do is.

Serializer serializer = new Persister();
serializer.write(instance, outputSteam)

To read you can do

Serializer serializer = new Persister();
Pojo pojo = serializer.read(Pojo.class, inputSteam)

And thats it! Its quite a powerful framework with many other features and annotations. It works for Android, Google App Engine, and any JDK 1.5+. It has no dependencies and is very light weight. For more information see the Tutorial .

Another option is Pulloid (pulloid.org). It relies on the XmlPull API which is included in Android. On the App Engine side you would need to use an XmlPull implementation such as XPP3 for now - I don't know if it's a show stopper or not.

Android lacks built-in support for XML generation, period. Android is stronger with JSON, since it can both parse and generate JSON documents.

In terms of patching XMLBeans, you may find it quicker to find some other package that has fewer dependencies. You cannot readily import any new code that resides in the java.* or javax.* packages.

You can use Castor . Just be sure, in Android 2.1, not to use default android SAXParser. You'll get namespace errors. You do this by defining the parser to be, for example, Xerces (and the you add the required JARS), in core.properties . In android 2.2 it may be ok. Note that if you create an xmlcontext for the unmarsheler with xerces, it still won't work, as the mapping itself would be parsed with android's SAX. It must be done at core (top level properties file) so that even the mapping is parsed by xerces. finally - performance is as slow as you can expect... :( Good luck SM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM