and want to learn how to work with xml files in c#.......
working with xml files in c#
Page 1 of 113 Replies - 1652 Views - Last Post: 22 May 2010 - 12:20 PM
#1
working with xml files in c#
Posted 21 May 2010 - 01:11 AM
and want to learn how to work with xml files in c#.......
Replies To: working with xml files in c#
#2
Re: working with xml files in c#
Posted 21 May 2010 - 01:22 AM
Take care.
#3
Re: working with xml files in c#
Posted 21 May 2010 - 01:47 AM
On the other hand I know your probably gonna ignore that so heres a pretty decent XML in C# tutorial Linky link of Linkyness
#4
Re: working with xml files in c#
Posted 21 May 2010 - 02:30 AM
Anyway: This and the second part have both been very helpful for me lately.
#5
Re: working with xml files in c#
Posted 21 May 2010 - 04:06 AM
AS an example, if you have a form with customer data.
public class CustomerData
{
public string FirstName;
public string LastName;
}
So save the data as XML your code will look something like this.
// Create an instance of the CustomerData class and populate
// it with the data from the form.
CustomerData customer = new CustomerData();
customer.FirstName = txtFirstName.Text;
customer.LastName = txtLastName.Text;
// Create and XmlSerializer to serialize the data to a file
XmlSerializer xs = new XmlSerializer(typeof(CustomerData));
using (FileStream fs = new FileStream("Data.xml", FileMode.Create))
{
xs.Serialize(fs, customer);
}
And loading the data back would be something like the following
CustomerData customer;
XmlSerializer xs = new XmlSerializer(typeof(CustomerData));
using (FileStream fs = new FileStream("Data.xml", FileMode.Open))
{
// This will read the XML from the file and create the new instance
// of CustomerData
customer = xs.Deserialize(fs) as CustomerData;
}
// If the customer data was successfully deserialized we can transfer
// the data from the instance to the form.
if (customer != null)
{
txtFirstName.Text = customer.FirstName;
txtLastName.Text = customer.LastName;
}
This post has been edited by stapia.gutierrez: 21 May 2010 - 04:11 AM
#6
Re: working with xml files in c#
Posted 21 May 2010 - 04:39 AM
http://msdn.microsof...y/bb387098.aspx
#7
Re: working with xml files in c#
Posted 21 May 2010 - 04:52 AM
and have been practicing c# from 4 days ....
and now i have problem with the xml part so......
#8
Re: working with xml files in c#
Posted 21 May 2010 - 04:53 AM
#9
Re: working with xml files in c#
Posted 21 May 2010 - 05:47 AM
stapia.gutierrez, on 21 May 2010 - 03:06 AM, said:
public class CustomerData{ public string FirstName; public string LastName;}
So save the data as XML your code will look something like this.
// Create an instance of the CustomerData class and populate// it with the data from the form.CustomerData customer = new CustomerData();customer.FirstName = txtFirstName.Text;customer.LastName = txtLastName.Text;// Create and XmlSerializer to serialize the data to a fileXmlSerializer xs = new XmlSerializer(typeof(CustomerData));using (FileStream fs = new FileStream("Data.xml", FileMode.Create)){ xs.Serialize(fs, customer);}
And loading the data back would be something like the following
CustomerData customer;XmlSerializer xs = new XmlSerializer(typeof(CustomerData));using (FileStream fs = new FileStream("Data.xml", FileMode.Open)){ // This will read the XML from the file and create the new instance // of CustomerData customer = xs.Deserialize(fs) as CustomerData;}// If the customer data was successfully deserialized we can transfer// the data from the instance to the form.if (customer != null){ txtFirstName.Text = customer.FirstName; txtLastName.Text = customer.LastName;}
eclipsed4utoo, on 21 May 2010 - 03:39 AM, said:
Nice posts guys, I learnt something from both of those
#10
Re: working with xml files in c#
Posted 21 May 2010 - 07:39 AM
sjdashing, on 21 May 2010 - 05:52 AM, said:
and have been practicing c# from 4 days ....
and now i have problem with the xml part so......
So......WHAT???? Are you going to ask a question? Are you going to post code? Or are you just using this like a LiveJournal?
You've been given good links and posts from which to learn. Is there something ELSE for which you're looking?
#11
Re: working with xml files in c#
Posted 21 May 2010 - 08:58 AM
What are you having troubles with precisely. Don't say: "Need help with the xml part".
#12
Re: working with xml files in c#
Posted 21 May 2010 - 01:37 PM
#13
Re: working with xml files in c#
Posted 22 May 2010 - 07:25 AM
~Shivern
#14
Re: working with xml files in c#
Posted 22 May 2010 - 12:20 PM
|
|

New Topic/Question
Reply




MultiQuote







|