title: Add attributes to XML element based on the input
body: <p>How can I check whether the value for an attribute is not null, inside the LINQ query. If it is not null then add the attribute to the XML element? </p>
  
  <p>for ex : First = AAA,  Last = BBB, Suffix = Jr. Then
  my XML should look like (As I didn't pass any value for Prefix and type they should not appear in the XML)</p>
  
  <pre><code>&lt;Subject&gt;
     &lt;/Name First= "AAA" Last ="BBB" Suffix="Jr"&gt;
  &lt;/Subject&gt;
  </code></pre>
  
  <p>Thanks
  BB</p>
  
  <pre><code>from i in DriverNames
    select new XElement(Subject,
               new XElement(Name,
                   new XAttribute("type", i.nameType),
          new XAttribute(First, i.First.ToString().Trim().ToUpper()),
          new XAttribute(last, i.Last.ToString().Trim().ToUpper()),
          new XAttribute(Prefix, i.Prefix.ToString().Trim().ToUpper()),
          new XAttribute(Suffix, i.Suffix.ToString().Trim().ToUpper())
                     ) )
  </code></pre>