hi..
here m getting error while retreiving data from xml file...the data is
storing ...bt for retreiving m getting error..
actually i have 3 edittexts and 2 buttons(Save and Retrieve) and 1
textview...for the first time when i enter values in 3 edittexts and click
on save button the data is storing and when i clicking Retreive button the
data is retreiving,...bt when for second time i give values in all edittexts
and click on save button it is giving error...
i left the application and again enter into application when i enter all
values in all edittexts and click on save button ...the data is storing...bt
here the problem is not retreiving...for further ly data is storing bt not
retreivng....the code is here:
Design:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/texteno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Eno"
android:layout_x="38dp"
android:layout_y="35dp" />
<EditText
android:id="@+id/etdeno2"
android:layout_width="142dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="119dp"
android:layout_y="20dp" />
<TextView
android:id="@+id/widget34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ename"
android:layout_x="36dp"
android:layout_y="80dp" />
<EditText
android:id="@+id/etdename2"
android:layout_width="133dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="123dp"
android:layout_y="70dp" />
<TextView
android:id="@+id/widget36"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="EAddress"
android:layout_x="38dp"
android:layout_y="134dp" />
<EditText
android:id="@+id/etdeadd2"
android:layout_width="133dp"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="119dp"
android:layout_y="124dp" />
<Button
android:id="@+id/Btndatasave1"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:text="Save"
android:layout_x="38dp"
android:layout_y="195dp" />
<Button
android:id="@+id/Btndataretreive1"
android:layout_width="93dp"
android:layout_height="wrap_content"
android:text="Retreive"
android:layout_x="169dp"
android:layout_y="193dp" />
<TextView
android:id="@+id/text1"
android:layout_width="270dp"
android:layout_height="70dp"
android:text=""
android:layout_x="35dp"
android:layout_y="250dp" />
</AbsoluteLayout>
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Data;
using Mono.Data.Sqlite;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace XmlData
{
[Activity(Label = "XmlDataTwo",MainLauncher=true)]
public class XmlTwo : Activity
{
EditText eteno, etename, eteadd;
Button btnsave, btnretrieve;
TextView text;
string path;
DataSet ds;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.XmlTwo);
eteno = FindViewById<EditText>(Resource.Id.etdeno2);
etename = FindViewById<EditText>(Resource.Id.etdename2);
eteadd = FindViewById<EditText>(Resource.Id.etdeadd2);
btnsave = FindViewById<Button>(Resource.Id.Btndatasave1);
btnretrieve =
FindViewById<Button>(Resource.Id.Btndataretreive1);
text = FindViewById<TextView>(Resource.Id.text1);
btnsave.Click += delegate { savexml(); };
// Create your application here
btnretrieve.Click += delegate { retrvXml(); };
}
private void savexml()
{
string path =
System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
"Emp6.xml");
StreamWriter stw = new StreamWriter(path,true);
XmlTextWriter xtw = new XmlTextWriter(stw);
xtw.WriteStartDocument();
xtw.WriteStartElement("ItemData");
xtw.WriteStartElement("Item");
xtw.WriteElementString("ItemNo", eteno.Text);
xtw.WriteElementString("ItemName", etename.Text);
xtw.WriteElementString("ItemCost", eteadd.Text);
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Flush();
Toast.MakeText(this,"saved
successfully",ToastLength.Long).Show();
eteno.Text = etename.Text = eteadd.Text = string.Empty;
xtw.Close();
}
private void retrvXml()
{
string path =
System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
"Emp6.xml");
XmlDataDocument xmldoc = new XmlDataDocument();
XmlNodeList xmlnode;
int i = 0;
string str=null ;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
xmldoc.Load(fs); //getting error for second time onwards
xmlnode = xmldoc.GetElementsByTagName("Item");
for (i = 0; i <= xmlnode.Count - 1; i++)
{
xmlnode[i].ChildNodes.Item(0).InnerText.Trim();
str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " | " +
xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " | " +
xmlnode[i].ChildNodes.Item(2).InnerText.Trim();
text.Text = str;
}
}
}
}
---------------
here i getting error at
xmldoc.Load(fs);
the error msg is also not displaying.......
i think it can show one record only...plz help me any one ...it became
torture for me...plz reply as soon as possible....
plz explain me in detailed...
--
View this message in context:
http://mono-for-android.1047100.n5.nabble.com/Error-while-retreiving-data-from-xml-file-tp5712920.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid