This is my first post here :-). I am developing an application for android in eclipse.
My question is I have put an XML file in sdcard with some elements like id,First name and lastname.
Form my UI i have one textbox and button. User will enter ID in the textbox and on click event of button I should fetch the data based on that ID. and display in TextView.
Any help please??
Thanks in advance. :-)
Here is a sample of XML file which is given to me,
<tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>1</ID>
<LastName>Family 1 (1-42-167)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>2</ID>
<LastName>Family 2 (1-4-16)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>3</ID>
<LastName>Family 3 (1-4-16)</LastName>
<OtherNames>FamMem3</OtherNames>
<DOB>01-01-98</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
SO is it possible that somehow I can pass an ID as a parameter and I can just display the rest of the information like name and dob etc on my screen?
Here is a complete example with source. You just to get the File using
File file = new File(Environment.getExternalStorageDirectory()
+ "your_path/your_xml.xml");
Then do the further processing.
If you need example for different types of XML Parsers you can download complete example from here.
Related
I have a question regarding of reading xml files in delphi.
I have read a few articles about it, but didn't find what I need anywhere, at least not that I'd notice.
Meanwhile, I read the arcticle on How to read data from xml file and display it over the text box in delphi language
However, two things:
first, in the first answer that Remy provided, I believe there is slightly mistaken code: Right after the "try", there is Vehicle := XMLDocument.DocumentElement; but I believe it should be XMLDocument1.DocumentElement instead. Am I right?
[sorry, can't post a comment since I don't have enough reputation.]
secondly, I don't quite get how do I change which record to show. In the example above, there were two records of "vehicle" in the xml file, however I only see like it's only called once, so here's my question, how and where do I define which record/node to read?
To be more specific on what I actually need:
I'm trying to read off a sms backup file, which is generated as an xml file, and has the structure as below:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<?xml-stylesheet type="text/xsl" href="sms.xsl"?>
<smses count="3">
<sms protocol="0" address="~number~" date="1385104712000" type="1" subject="null" body="Message 1 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 8:18:32 AM" contact_name="My contact 1" />
<sms protocol="0" address="~number~" date="1385104912000" type="2" subject="null" body="Message 2 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 8:38:32 AM" contact_name="My contact 2" />
<sms protocol="0" address="~number~" date="1385106412000" type="1" subject="null" body="Message 3 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 9:18:32 AM" contact_name="My contact 1" />
</smses>
How could I read these correctly? Notice, that there might be repeatable "address" values.
I'd like to add every different contact/number/"address" as an Listbox item, so I can select the contact, and later show the conversation via other elements..
I was thinking of reading the whole xml file to an array of record with length set by the first data in xml, , so I can later access this data directly from the program, as well as maybe write it to database, so the one could make/create organized database of all sms backup xml's he/she has...
With the database etc I don't expect any problems, just need to read the file to the memory first of all.
Any help would be appreciated. Thanks! :)
i have to make a notepad where i write,edit,clear the text.
this notepad need to save on sd card as an xml file.
i also need to read the file when it will in sd card.
i am new in android and i can not understand how to manage it.
<Title>
<edittext>
<path>(xml file saved in sd card)...</path></edittext></title>
then this xml need to call by activty.
is there any possible way or any easiest way to do it?
There's an Android notepad tutorial: http://developer.android.com/resources/tutorials/notepad/index.html
It would be a good place to start.
If you are trying to load the notepad text, then you'll need to do that in code. Something like
<EditText
android:id="#+id/editor"
.../>
Then in code,
String savedText = loadTextFromFile();
EditText editor = (EditText)findViewById(R.id.editor);
editor.setText(savedText);
Then you just need to write the loadTextFromFile() method to actually get the notepad text. This is the same as you would do it in Java.
I have been working on android for about 4 months, i am working on a simple application to download a xml file placed on local server to the sdcard. I have done this part successfully, now i want to edit the data present in that xml. To get a more clear picture here is a sample code of my xml file ...
<seekbar>
<value>
50
</value>
</seekbar>
now am reading the value 50 by xml parsing and updating the value of seekbar as 50. Nowi change the value of seekbar to 100 through GUI. So when i click on save button i want that the value 50 should be replaced by 100 in the xml present in the sdcard. I have learnt about the sdcard permission but i am not getting about how to go for this modifying part.. Will i have to parse the whole xml again...??? Please help guys....
You can load the xml into a DOM Object. modify the value or value node and write the new DOM object back to the file.
in my app i am sending when i click a button it goes on to a url and it returns back an xml file. The xml file is as follows
<search>
<data>
<userid>1</userid>
<name>Jean</name>
<address>dbvsvksn</address>
<dob>Mar 3</dob>
<country>us</country>
</data>
<data>
<userid>2</userid>
<name>Anne</name>
<address>dbvsvksn ,</address>
<dob>Jun 2<dob>
<country>us</country>
</data>
<data>
<userid>3</userid>
<name>J</name>
<address>dbvsvksn ,</address>
<dob>Dec 6<dob>
<country>us</country>
</data>
</search>
From this xml file i am listing out the name's in a list view in an activity. In the list view when a name is clicked it moves over to a new activity where i want to display the correct address, country and dob.
I am able to get the xml file and list out the names in a list view, but i don't know how to display the exact tag related to the name selected , please help me. How to do this....
You say you can get the xml file and list out the names, so you apparently are parsing the xml. Are you using one of the XML parser classes (DOM or SAX)? If so, presumably you are building some sort of data structure based on the parsing (probably an array, judging from the XML fragment you posted). Use the index of the selected name to index into the array and retrieve the rest of the data you need.
Perhaps if you posted some code showing what you've tried, we can provide more specific help.
you can use textview. The number of userid's is there same number of textview.One for each userid,name,address,dob & country. Just add these in tablerow & just check which row is clicked just pass all information of that click in intent & you are able to display all info.
Using this tutorial at section 5.5, I attempted to "Assign the 'celsius' string attribute to the 'text' property of the first radio button and "fahrenheit" to the second"
The "Resource Chooser" (called, by mistake (?), "Reference chooser" in the above article) is displayed but...I can choose only between two strings : "app_name" and "hello". "celsius" and "fahrenheit" attributes are not proposed.
How do you solve this issue?
In the res/values folder should be an XML file called strings.xml When you open this you will see the values you referred to ("app_name" and "hello"). Make an entry similar to them like this:
<string name="celsius">Celsius</string>
You could just hard code the text into the text property you are referring to but Android provides this way to store strings of text in an XML file so that they can be 1) easily found in one spot and 2) easily translated if required later. So it is recommended to do it "the Android Way." This is explained in section 5.3 of the tutorial you linked to.
Now you should be able to reference them by the element name (celsius) as you were trying to.
The strings.xml file has to be SAVED once modified in order to have its modifications taken into account !