Retrieve data from XML using Linq

Posted by Komminedi under XML on 12/24/2009 | Views : 2302 | Status : [Member] | Replies : 2
How to retrieve data from XML using Linq ?

I have a requirement that I am using xml file for a survey application. In that I need to retrieve the data from XML. I tried with XPATH. But my problem is not solved. Can you please give an example on LINQ?

Thank you




Responses

Posted by: Mehulthakkar1 on: 12/29/2009 [Member] Starter

Up
0
Down
Hi,

You can use linq following way:

XElement xe; // XElement will be at System.Xml.Linq

xe = XElement.Parse(sw.ToString());//where sw is a XML string

List<string> Resources = (from rs in xe.Descendants("Resources") select rs.Element("FirstName").Value + " " + rs.Element("LastName").Value).ToList<string>(); //where resources are the tuples and firstname and lastname are the columns
foreach (string s in Resources)
lstResources.Items.Add(s);




Thanks,

Mehul Thakkar

Komminedi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 1/2/2010 [Member] Bronze

Up
0
Down
ref. this link
http://blogs.techrepublic.com.com/programming-and-development/?p=594

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Komminedi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response