Xsd2Code using Mono for Android - android

I am trying to read XML->POCO using an xsd, so I use the Xsd2Code generator, giving me a simple Xml Serializer code. When I dry-test this in the regular Windows world, with my XML I have no issues getting around 18 POCOs from the xml-file.
The fun begins in the Android world. I see that the loading of the XML file is done perfect, no issues there I have a perfectly sound XML string. When the Deserialization is complete I only get the first element in the xml file, missing 17 POCOs.
What is wrong here? Is the Xml Serializer/Deserializer working diffrently in Mono?

I guess you should find a reduced testcase (simple program) that works on .NET and fails in MonoDroid, and attach it to a new bug in http://bugzilla.xamarin.com/

Related

How to get the inner tags from an XML file?

I'm sitting there for quite a while now, trying to process my xml file (similar to the one below). I want to check all tags, if is equal to a variable, and if so, then running readEntry() on the tag.
I followed this example: https://developer.android.com/training/basics/network-ops/xml.html
I also found this Article(Difficulty with XML nested tags with XMLPullParser in Android deals with this topic.
I have already tried a few things but get either nothing or XmlPullParserException.
A Example of my XML:
<VpMobil>
<Kopf>
...
</Kopf>
<FreieTage>
...
</FreieTage>
<Klassen>
<Kl>
<Kurz>5</Kurz>
<Pl>
<Std>
<St>1</St>
<Fa>Fa1</Fa>
<Le>NAME</Le>
<Ra>1009</Ra>
<Nr>131</Nr>
<If/>
</Std>
<Std>
<St>2</St>
<Fa>Fa2</Fa>
<Le>NAME</Le>
<Ra>1004</Ra>
<Nr>132</Nr>
<If/>
</Std>
</Pl>
</Kl>
<Kl>
<Kurz>6</Kurz>
<Pl>
<Std>
<St>1</St>
<Fa>Fa2</Fa>
<Le>NAME</Le>
<Ra>1046</Ra>
<Nr>131</Nr>
<If/>
</Std>
<Std>
<St>2</St>
<Fa>Fa3</Fa>
<Le>NAME</Le>
<Ra>1012</Ra>
<Nr>132</Nr>
<If/>
</Std>
</Pl>
</Kl>
</Klassen>
</VpMobil>
I would be very grateful if someone could explain to me how I can achieve this. Thanks in advance
You can use Jackson library to parse XML, it is as easy as parsing Json File. this tuto will help you to figure out.
However, bescause it is is a nested xml, you will need some nested POJOs to achieve parsing.
After a few more unsuccessful attempts, I got the idea to convert the XML into a JSON (Convert XML to JSON object in Android) and continue working with it. That worked then.

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.

MVEL2 on android throws exception

Did anyone has experience with MVEL2 on android?
i've tried out the same code with a simple java program and later on android:
The following exception is thrown when executed on android:
E/AndroidRuntime(30793): java.lang.ExceptionInInitializerError
I tried the example from the mvel website:
String template = "Hello, my name is #{name.toUpperCase()}";
Map vars = new HashMap();
vars.put("name", "Michael");
System.out.println(TemplateRuntime.eval(template, vars));
If theres no solution could anyone suggest a template engine which works with android
and supports iteration?
MVEL2 tries to substring the first 3 characters of the system java.version property when initializing the parser, and under Android the version is 0. That causes a bunch of exceptions which eventually cause the ExceptionInInitializerError.
If you want to force the java.version property, you can simply set it yourself:
System.setProperty("java.version", "1.6");
I have no idea what kind of odd side effects this may cause for Android, but at least it gets the MVEL parser up and running without throwing exceptions!
System.setProperty with "java.version" key seems to be read only propery in android, so it won't work.
i've tried to integrate MVEL 2 into android with no success, try using EVAL lib

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.

Categories

Resources