want to query below xml
<courseList filedUnder="Courses">
<category code="4wd" title="4wd Operation">
<product code="lr" title="4wd Bush Driving">
<duration>1 Day</duration>
</product>
<product code="hr" title="4wd Defensive Driving">
<duration>1 Day</duration>
</product>
<product code="sr" title="Self-Recovery">
<duration>1 Day</duration>
</product>
</category>
</courseList>
for now am doing something below:
var list = (from x in xd.Descendants("product").Attributes("title")
select new { Title= x.Value}).ToList();
which returns just : title value
What i want is in same query to return Duration value too.
How can this be achieved.
Thanks
Currently you’re selecting the attributes instead of the elements. To include the duration, you’ll need the whole element.
(Note that this doesn’t do any sort of error checking – there’d better be a title attribute and a duration element…)