I created a xsd and I created Java objects using Castor. Then I imported this in my Android project and tried to build an XML from the object, using the marshal method.
Marshaller.marshal(v, writer);
I received some wired exception trouble processing "javax/xml/parsers/DocumentBuilder.class":...
So my question is Can I use Castor inside Android, If yes how can I work around this.
If no, what is the neat solution available to convert object to xml and xml to object in Android, similar to Castor.
Thanks in Advance.
I personally do not have any experience with Castor but from the website it would seem that it has dependencies which android does not support and therefore cannot be used inside android.
I ended up using Simple xml from simple.sourceforge.net/home.php. This looks light suitable for Android. But this will not create Java objects for your xsd. You have to create them on your own. Is there a way to build these objects directly from xsd compantible with Android?
Related
I'm working to create a library for my app in C. I want to parse a XML file in my code.
So, how can i do it in C ?
I know its java implementation but how can i parse a XML in my C code ?
What are the libraries that can be used for the purpose ?
I suggest Expat, I've used with many projects and it is very simple to use and has extremely small overhead. Its code base is also quite stable.
Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document (like start tags).
However with every other external project mentioned, you need to build it yourself.
you should use c library for parsing xmls. here are some famous library links.. you can check
http://www.jclark.com/xml/expat.html
http://www.xmlsoft.org/
http://tibleiz.net/asm-xml/benchmark.html
you can find many other library to parse xml. But if you have any lightweight parsing task then you can use
http://www.minixml.org/
I have used http://www.minixml.org/ so i suggest to use this. Minixml is quite simple and easy to understand and use.
So you can download whole code of minixml and cross compile it for Android using Android toolchain or android NDK. And now Link that library to your jni code and use its API in your c code.
Just refference for includeing 3rd party library in jni code see
How to link any library in ndk application
In my Android app, I need to talk to a webserver that expects marshalled objects of complex classes. These custom classes were produces from a WSDL file, so they already come with annotations. The server uses JAXB for marhalling and unmarhalling.
So, on the client side, using JAXB, I would simple to this:
JAXBContext jc = JAXBContext.newInstance("schema_definition_path");
Marshaller m = jc.createMarshaller();
Unmarshaller u = jc.createUnmarshaller();
...and then use the Marshaller and Unmarshaller instances to work serialize/deserialize the custom objects.
Since, it's not a great idea to use the heavy-weight JAXB lib in mobile apps, I am looking for an alternative to do what JAXB does for me here.
I checked out Simple XML Serialization, but that doesn't seem to provide this kind of functionality. I can only give a class to the unmarshaller instead of the schema definition path. Doing this results in an incomplete xml document, containing only the root element.
Can anyone point me in the right direction, please? Is this even possible? Should I use a different lib - which one? I am I just misusing SimpleXML?
Since I couldn't find any better way (see comments to the original question), I decided to manually convert the Objects using the XML Pull API implementation included in Android.
Here is a short tutorial on how to use it: http://www.ibm.com/developerworks/opensource/library/x-android/
I'm not saying it's a good way, but it's the only thing I can think of that will work and where I don't have to touch the original classes.
I'm new to game programming, and am trying to write the Map storage portion of my 2D tile based game on android. At first, my plan was to store the maps in XML. I found a tool (http://www.mapeditor.org/) that stores the created maps in a format close to what I was thinking. However, it seems like Android is very limited when it comes to XML. I'm used to working with XML Beans which doesn't work on Android, though I admit XML Beans would probably be too resource heavy for mobile devices anyways. However, after searching around for XML parser options, it seems like even basic XML validation isn't even included by default with the Android SDK. It's starting to look like XML might not be the best answer.
Does anyone know of a good standard way to store map configuration besides XML? Or some strong XML tools available in Android that handle validation (against a defined schema), and preferably simple parsing? I would really like to avoid defining my own flat file text format for maps...
Check out AndEngine. If I remember correctly AndEngine already has the classes needed to load a map from an XML file for rendering.
As far as a standard way to store map configurations, I would say XML is the way to go. I mean you could create your own format, but why re-invent the wheel?
I parse XML in Android with javax.xml.parsers.DocumentBuilderFactory and various other XML parts. It hasn't failed me yet!
For example see: http://www.developerfusion.com/code/2064/a-simple-way-to-read-an-xml-file-in-java/
I am working on a project in Android now that involves parsing XML from a local file.
I have done XML work extensiely in flex and have become used to the power and flexibility of E4X and it's capabilities. I wonder now if I can do something similar in android or will I be forced to parse the XML manually?
Thanks
Quoting #Andreas_D:
E4X is a language extension, XML is treated like a primitive. E4X is not just for parsing XML, it's using XML as real types.
This can't be simulated or done with a Java 'framework', it would require a language extension for Java.
And, since Android does not have JAXB, you don't have that, either.
You have your choice of DOM, SAX, and the XmlPullParser, plus any third-party Java libraries you can find that have been ported to Android and fit whatever size constraints you may have.
check this out-
Working with XML on Android
I would like to serialize an object to XML inside Android.
Any libs suggested?
PS: Already tried XStream, but it doesn't serialize enums correctly with Android. The issue is here: Serialization problem with Enums at Android
Have you tried simple http://simple.sourceforge.net/ it is working well for me, correctly handles enums, the jar is quite large though 320k.
Unfortunately I don't think there is a good solution for xml serialization of objects in Android yet. Most of the existing solutions are too heavyweight for use in mobile apps, and depend on things Android doesn't support.
For an overview of XML options, see working with xml in Android.
It's not XML, but you might want to use Google's GSON library to serialize objects. It's what they recommend in the their documentation as an alternative to Serializable:
JSON is concise, human-readable and efficient. Android includes both a streaming API and a tree API to read and write JSON. Use a binding library like GSON to read and write Java objects directly.