how to check an attribute value when that attribute may or may not exist

Discussion in 'Database, XML and Reporting' started by DN Admin, May 10, 2012.

  1. DN Admin

    DN Admin
    Expand Collapse
    Staff Member

    United States
    Aug 7, 2010
    Likes Received:
    Trophy Points:
    Joliet, IL U.S.A.
    My LINQ statement looks like
    <pre class="prettyprint List<XElement> filteredset = (from file in matchingsets.Elements<XElement>(Global.xnFile) where (((string)file.Attribute(Global.xnToKeep).Value != "*")
    && ((string)file.Attribute(Global.xnProtected).Value != "*") & & File.Exists(file.Attribute(Global.xnPath).Value)) select file).ToList<XElement>(); </pre>
    My problem is that neither file.Attribute(Global.xnToKeep). nor file.Attribute(Global.xnProtected) are guaranteed to exist in file. So, I need to test their existence before testing what their value is. How do I do that in a LINQ statement?<br/>

    View the full article

Share This Page