<Customers> <Customer id="1" orderdate="4/1/1968">Paul Koch</Customer> <Customer id="2" orderdate="7/5/1988">Bob Kelly</Customer> <Customer id="3" orderdate="3/24/1990">Joe Healy</Customer> </Customers>
XDocument myDoc = XDocument.Load(@"C:\sample.xml"); |
Method 1
you can use var type variable and through iteration you can get the result. this method is good when you have more than one record.
var q = from c in myDoc.Descendants("Customer") where (int)c.Attribute("id") == 2 select c; |
foreach (XElement item in q) { String id =item.Attribute("id").Value; String orderdt = item.Attribute("orderdate").Value; String name = item.Value; } |
if you know it is a single value (assume id is unique for customers)
Comments