Are there any StAX implementation for android? - 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 ?

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).

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.

Related

How to generate/ serialize a Xml using XStream?

I have a BO class which is not annotated for XStream library and i have to serialize a xml from this class with only two fields.
do i need to specify all other field in omit ?
or can i specify which fields are needed to serialize?
If you want to do it using normal way, you should specify all fields as omitted.
If you take a look at http://jira.codehaus.org/browse/XSTR-569 there was a ticket about it from long time ago that was closed as 'not a bug' ('XStream is a serialization tool, not a data binding tool').
There is another question which shows some workarounds to get it working the way you want, though it might not be so clean to do it, since the idea of XStream is not to work this way. Take a look: How to make XStream skip unmapped tags when parsing XML?

xml beans in android

I want to use xml beans in Android. I searched around one day in google and i some places read , i can't use xml beans in Android and Android not have this and now i am confused! I dont know, i can use this or not and if i can't use this, What should i use instead of xml beans? I don't want use maven.
xml beans configuration is just in spring?
I can use xml beans in Android? if yes xml beans from spring?
I read, use xml beans could slow my App. this is true? if yes what should i use instead of this for increase performance app?
I goal from use xml beans this is:
I want to create a bean xml file that i set all of my classes(with my packages) and i want in id tag in bean tag, set a method name from my class. like below: () and with this, i can get SMS method from sendingSMS class with reflection. I mean i can send method name and parameter from this method to reflection class and then call method. This is a training sample for learning android and java bean and reflection in android and then use this in real project.
and I see use xml beans in java like this link (use beans in java) but i want use this in android
Thanks for your help :)
Maybe you can user XStream Library in Android
Xml Parse would slow your app? No,I think it decides your parse method.

xml to sqlitle loop in android

Hello all my second question here so be gentle :)
I'm still learning java and android, I'm learning it on my little project but I hit kind of logical wall.
I have XML file
<shift_plan>
<plan>
<agent data="John Smith"/>
<date data="6 Jan"/>
<shift data="M-3"/>
</plan>
<plan>
<agent data="John Smith"/>
<date data="7 Jan"/>
<shift data="M-3"/>
</plan>
<plan>
<agent data="John Smith"/>
<date data="8 Jan"/>
<shift data="M-3"/>
</plan>
</shift_plan>
on a web and I want to make a loop that would paste each data to function that put it to db. I have the function and working db so it looks like updateBD(agent, date, shift ) but how would I go about parsing the xml but to parse the 3 variables than put them in that function and than go again for the next 3 etc...until end of xml
I might be not making much sense I know, this must be something very simple I'm sure but I need really kick in the right direction..
Thanks for any answer,
Vlad
Android supports the XmlPullParser API right out of the box. It is an excellent solution for parsing XML documents in Android apps because you can start pulling information from the document right away (it's a streaming XML parser) and its pull-style API is a lot easier to use than that of a push-style streaming XML parser when all you need to do is parse the document into objects.
I am not sure if this is still true in Android 3 and 4, but the Android 2.3.x and earlier implementation of XmlPullParser (from the Apache Harmony project) does not support getPrefix() or getAttributePrefix(int index). Though, this shouldn't affect you because you are not using XML namespaces.
EDIT: Examining the git trees corresponding to the platform_frameworks_base tags, it appears that Android 3.2.4 and earlier have the XmlPullParser implementation from the Harmony project whereas beginning with Android 4.0, the implementation switched to kXML2.

Android - Getting data from XML file on the web

I need to get data from an XML file in Android. On the iPhone environment, my code is:
NSURL *thisURL = [[NSURL alloc] initWithString:#"http://www.xxx.com/file.xml"];
NSArray *myArray = [[NSArray alloc] initWithContentsOfURL:providerURL];
myArray is now an array of dictionary items initialized with contents from file.xml.
Is there any way to do this in Android? Can someone point me to doc or sample code?
I'm new to the Android environment and just need some direction.
Thanks,
Kevin
See Working with XML in Android for a variety of methods for dealing with XML. Which method to use depends on how big your XML is, and what you want to do with it. '
I'm not sure how it makes any sense to turn XML into an array, so no, none of the methods do that. If you want something similar to that, use Json instead of XML.
After a bit of research, it appears to me that using the Simple XML Serialization framework is going to be my best bet, especially since I do have a relatively simple XML file to read. The result will be a 'list' class with several 'entry' classes which seems like a viable way to handle this...probably better than having an array of classes as was done in the iPhone app.

Grabbing XML File Data from a Website

Just wondering what would be the best way to grab the following data and parse it.
Here's an example of some the data I want to pull.
<?xml version="1.0" encoding="UTF-8" ?>
<eveapi version="2">
<currentTime>2010-11-19 19:23:44</currentTime>
<result>
<rowset name="characters" key="characterID" columns="name,characterID,corporationName,corporationID">
<row name="jennyhills" characterID="90052591" corporationName="Imperial Academy" corporationID="1000166" />
</rowset>
</result>
<cachedUntil>2010-11-19 20:20:44</cachedUntil>
</eveapi>
I've seen some examples on how to parse XML data but they are all based on if statements and that's a lot of hard coding is there a more generic way to do this?
Parsers are quite hardcoded that's the way they work. You can only check if a certain tag matches a certain pattern and then decide what to do. Especially for simple documents like yours that is absolutely no problem.
If you have more than one type of document to parse then I recommend reading this SO answer.
The "parsing", taking the term literally, is easy. Parsing is the process of taking a text string (in your case, from an http response) and turning it into a data structure such as an XML document tree. That process is handled for you by an XML parser, and you typically don't need to worry about it.
The part you're facing is how to query data from the parsed XML document, right? The easiest way to depends greatly on what you need to do with the data. But XPath is a good way to select data without a lot of verbose if statements and get-child function calls.
See also this question on using XPath in Android.

Categories

Resources