I am working on an app that will, among other things, manage a custom
XML-based config file. I want to be able to check for the existance of
a particular element before writing the setting. I have a file like
the following:

<ConfigurationSettings>

     <Settings>
          <Setting SettingName="Setting1" />
     </Settings>

</ConfigurationSettings>

For some reason that I cannot see (likely I am missing something
obvious) the following code is not succeeding in finding the existing
"Setting" element in the "Settings" section.

            XDocument xmlDoc = XDocument.Load(CONFIG_FILE);

            IList<XElement> chkForElement = xmlDoc.Descendants
("ConfigurationSettings")
                .Where(x => x.Elements("Setting").Any())
                .ToList();

            return chkForElement.Count > 0;

With the above supplied XML sample, should this not return True? When
I debug, I see the XML loaded properly in the first line. But, the
chkForElement.Count is always 0.

Any help with this would be greatly appreciated.

Thanks in advance!

rbr

Reply via email to