Quickest way to gather hundreds of questions and answers into xml file? - android

I am making a program that has lots of brainteaser questions for android. I need to gather lots of questions into an XML file or some other format any ideas on how to do this?

If you want to hook up a Java object to an XML representation then take a look at Simple XML. It will work on Android.
With that you could create a simple 'Question' class with a 'description' string and an 'expectedAnswer' string and go from there.

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.

how to get html source code in android?

What would the best approach to :
get html codes by calling url and displaying it in some views
if i would be editing the values against title tag, it must be automatically updated in the url link?
How to do this?
Check out the JSoup cookbook.
http://jsoup.org/cookbook/
This has a lot of good information in it and should be able to answer most of your questions.
You are probably looking for something along the lines of this: http://jsoup.org/cookbook/input/parse-body-fragment

Trying to pull API into LinearLayout Android APP

I am a beginner of Android apps and am using Eclipse. I have found some larger samples of pulling APIs but I cannot find a simple one to get started with. I simply want to pull from an XML file on the web (by using an API KEY) and throw it in a LinearLayout (Vertical). I can then go from there, anyone know of any? Below is a sample of my XML:
<xmldata>
<Products>
<ProductCode>ITI-GR12</ProductCode>
<ProductName>Granada 9-3/4" Narrow Rim Platter</ProductName>
<ProductPrice>64.4000</ProductPrice>
</Products>
</xmldata>
I am assuming you are looking for mechanisms which help you to parse XML and extract data from it...Voila here is a link to get you started with different ways of doing it...
http://www.ibm.com/developerworks/opensource/library/x-android/
Good luck!
your question is not easy as you will have quite a lot of programming to achieve what you want.
Here are the steps :
read your data using sax
fill a data structure of your own (build a
class, data members will be filled by
previous parsing)
build an activity, use a layout you define to
show all UI fields you think you need
to display your data
fill the content of each view using the data
structure you filled on step 2.
If you are a beginner, I suggest you first understand steps 3 and 4, having fun with UIs, then try to understand how you could download your file, parse it and fill some data class to provide content for the views.
Regards,
Stéphane

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