Hi.

.i wnt to use xml file as data storage...can any one tell me how to
store data to xml file from mono for android edit texts ....i have 2 edit
text controls when i click on save button the data in the edit text have to
store into the xml file...m very new to mono for android...where to create
xml file and where to write code...explain me in detailed step wise...its
very need to me...

The (internal) creation of the XML file is the same in monodroid as it is in C# as is the reading and writing to the device (XmlReader and XmlWriter classes).

The creation is simple enough. I'll call your save button btnSave for argument here with the EditText controls edit1 and edit2

btnSave.Click += delegate { saveToXml(edit1.Text, edit2.Text); };

private void saveToXml(string text1, string text2)
{
string path = System.IO.Path.Combine(System.Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments),"myXMLfile.xml");
try
{
XmlTextWriter textWriter = new XmlTextWriter(path);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("string1");
textWriter.WriteStartElement(text1);
textWriter.WriteEndElement();
textWriter.WriteStartElement("string2");
textWriter.WriteStartElement(text2);
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();
}
catch (IOException ex)
{
Console.WriteLine("Exception thrown : {0}", ex.Message);
}
}

(or however you want to write the XML document - this is a quick and simple method)

You will need it have

using System.Xml;

at the start of the file ;)

HTH

Paul

--
"Space," it says, "is big. Really big. You just won't believe how vastly, hugely, mindbogglingly big it is. I mean, you may think it's a long way down the road to the chemist's, but that's just peanuts to space, listen..."
Hitch Hikers Guide to the Galaxy, a truly remarkable book!

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to