I have the following XML and that is loaded using the path variable
<testdata>
<payloaddata>
<Data Name="testdataone">
<Id>101</Id>
<Value>data1</Value>
</Data>
<Data Name="testdata2">
<Id>102</Id>
<Value>2</Value>
</Data>
</payloaddata>
<VerifyData>
<Data Name="veridyData">
<Id>301</Id>
<Value>true</Value>
</Data>
</VerifyData>
</testdata>
I need to retreive the value element data with id 101. Meaning if queried for "101" i should get "data1".
I have written the following is this fine, or can this be more optimized? or written better? I am new to LINQ
XDocument document = XDocument.Load(path);
var query = from data in document.Descendants("payloaddata").Descendants("Data")
where (string)data.Element("Id").Value == "101"
select new
{
payloadData = data.Element("Value").Value
};
foreach (var employee in query)
{
Console.WriteLine(employee.payloadData);
}