I’ve got an xml document of the following structure which I’m trying to query in C# with LINQ to xml
<recurrence>
<rule>
<firstDayOfWeek>mo</firstDayOfWeek>
<repeat>
<weekly mo="TRUE" fr="TRUE" weekFrequency="1" />
</repeat>
<repeatForever>FALSE</repeatForever>
</rule>
</recurrence>
I’m trying to query it to determine information about what’s contained in the xml and building an object based on that.
Within the “repeat” element the title of the element within can be weekly (as in the sample) daily, monthly or yearly.
I’m having trouble selecting the weekly element. As I’m not sure it’s going to be called weekly I’m trying to below
XDocument info = XDocument.Parse(source.RecurrenceData);
var data = from d in info.Descendants("recurrence").Descendants("rule").Descendants("repeat")
select d;
var element = data.Elements().First();
This is always coming out as null. What would be the easiest way for me to select this element, whether it be a daily, weekly, monthly or yearly element and then determine the various attributes that may or may not be contained within in it?
I have placed the following code in a console application and the element is not null. Are you sure that your
source.RecurrenceDatais correct?