I'm new to Linq to XML and eager to learn, but getting a little frustrated. I'm also using LinqPad to test out syntax:
I have a simple xml file "tasks" with elements "task" Each "task" contains basic info include a CustomerId. I want to query the xml file for a particular customerId and return that entire Element so that I can then populate a data Structure. I can't seem to get it work.
tasks><task><TxnID></TxnID><TxnDate>7/28/2016</TxnDate><EmployeeName>My Name</EmployeeName><EmployeeID>20000-931786752</EmployeeID><CustomerName>My Best Client</CustomerName><CustomerID>800002F5-1294851965</CustomerID><ItemServiceName>Consulting</ItemServiceName><ItemServiceID>40000-931904334</ItemServiceID><Notes>test</Notes><isBillable>false</isBillable><LapseSeconds>0</LapseSeconds></task><task><TxnID></TxnID><TxnDate>7/28/2016</TxnDate><EmployeeName>My Name</EmployeeName><EmployeeID>20000-931786752</EmployeeID><CustomerName>ICON</CustomerName><CustomerID>800003B3-1464136019</CustomerID><ItemServiceName>Consulting</ItemServiceName><ItemServiceID>40000-931904334</ItemServiceID><Notes>Second task</Notes><isBillable>false</isBillable><LapseSeconds>0</LapseSeconds></task></tasks>
My simple task Query is:
var tasks = XElement.Load("C:\\Development\\TaskTracker\\TaskTracker\\TaskTracker\\bin\\Debug\\Tasks.xml"); IEnumerable<XElement> thisTask = from el in tasks.Elements("tasks") where tasks.Element("CustomerListID").Value == "800003B3-1464136019" select el; tasks.Dump();and it returns empty. So, how to do this simple query? Thanks