Return List Value From Xml File.

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 767
hi

I have post the Code for Xml For Read and assign List Collection.

refer this url : http://buddylindsey.com/reading-data-from-xml-file-using-c/


public List<Contact> RetContact()
{
List<Contact> lst = new List<Contact>();
XmlDocument Doc=new XmlDocument ();
Doc.Load(Server.MapPath("XMLFile2.xml"));
XmlNode root = Doc.SelectSingleNode("//contacts");
XmlNodeList XmlNdlist = root.SelectNodes("contact");

foreach (XmlNode n in XmlNdlist)
{
Contact c = new Contact();
c.Guid = n.SelectSingleNode("Guid").InnerText;
c.Name = n.SelectSingleNode("name").InnerText;
c.Email = n.SelectSingleNode("email").InnerText;
lst.Add(c);
}
return lst;
}

protected void Bt_Submit_Click(object sender, EventArgs e)
{

List<Contact> lstContlist = new List<Contact>();
lstContlist = RetContact();
}

Comments or Responses

Login to post response