You are just overriding the old entries instead of appending new entries to your XML, that is what is your problem is.
I've made a sample which you can see here: https://gist.github.com/Cheesebaron/5029622 which works as intended. I am not sure if my method of writing the XML is the most optimal and clean, but it works. Med Venlig Hilsen / With Best Regards Tomasz Cielecki http://ostebaronen.dk On Mon, Feb 25, 2013 at 1:41 PM, krish <kickr...@gmail.com> wrote: > > > > hi...i m working on saving and retreiving of xml file...i have 3 edittexts > and two buttons....by entering values in all 3 edittexts and click on save > button,the data will saved to xml file...when i click on retrieve button > the > stored data shud display in textview(like label)...the data is saving to > xml > file and my problem is when i click on retreive it will shows only last > inserted record...not alll the records i inserted....and my code for saving > and > retreiving is : > > namespace XmlData > { > [Activity(Label = "XmlDataOne",MainLauncher=true)] > public class XmlOne : Activity > { > EditText eteno, etename, eteadd; > Button btnsave, btnretrieve; > TextView text; > string path; > string sbs=""; > protected override void OnCreate(Bundle bundle) > { > base.OnCreate(bundle); > SetContentView(Resource.Layout.XmlOne); > // Create your application here > eteno = FindViewById<EditText>(Resource.Id.etdeno1); > etename = FindViewById<EditText>(Resource.Id.etdename1); > eteadd = FindViewById<EditText>(Resource.Id.etdeadd1); > btnsave = FindViewById<Button>(Resource.Id.Btndatasave); > btnretrieve = > FindViewById<Button>(Resource.Id.Btndataretreive); > text = FindViewById<TextView>(Resource.Id.text); > btnsave.Click += delegate { savexml(eteno.Text, etename.Text, > eteadd.Text); }; > btnretrieve.Click += delegate { retrXml(); }; > } > > private void retrXml() > {string path = > > System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),"Empp.xml"); > XmlDocument doc = new XmlDocument(); > doc.Load(path); > XmlNode root = doc.DocumentElement; > StringBuilder sb = new StringBuilder(); > XmlNodeList nodeList = root.SelectNodes("Employee"); > foreach(XmlNode node in nodeList){ > > sb.Append("Eno:"); > sb.Append(node.SelectSingleNode("Eno").InnerText); > sb.Append("Ename:"); > sb.Append(node.SelectSingleNode("Ename").InnerText); > sb.Append("Eadd:"); > sb.Append(node.SelectSingleNode("Eadd").InnerText); > sb.Append(""); > text.Text = sb.ToString(); > } > > // throw new NotImplementedException(); > } > > private void savexml(string p, string p_2, string p_3) > { > if (eteno.Text != "" && etename.Text != "" && eteadd.Text != > "") > { > //throw new NotImplementedException(); > string path = > > System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), > "Empp.xml"); > try > { > XmlTextWriter xWriter = new XmlTextWriter(path, null); > xWriter.WriteStartDocument(); > xWriter.WriteStartElement("EmployeeDetails"); > xWriter.WriteStartElement("Employee"); > xWriter.WriteElementString("Eno", p); > xWriter.WriteElementString("Ename", p_2); > xWriter.WriteElementString("Eadd", p_3); > xWriter.WriteEndElement(); > xWriter.WriteEndElement(); > xWriter.WriteEndDocument(); > xWriter.Close(); > Toast.MakeText(this, "xml saved successfully", > ToastLength.Long).Show(); > etename.Text = eteadd.Text = ""; > } > catch (IOException ex) > { > Toast.MakeText(this, ex.Message, > ToastLength.Long).Show(); > } > } > else { Toast.MakeText(this, "plz fill all fields properly", > ToastLength.Long).Show(); } > } > } > } > > plz give me in detailed code for retreiving all the records ...have to i > use for loop or any thing..plz tell me suggestable code...reply as early as > possible > > > > -- > View this message in context: > http://mono-for-android.1047100.n5.nabble.com/Enhancement-in-Xml-Retreive-code-tp5712932p5712934.html > Sent from the Mono for Android mailing list archive at Nabble.com. > _______________________________________________ > Monodroid mailing list > Monodroid@lists.ximian.com > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid >
_______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid