One way is to filter out the list before you process it:
XElement[] elements = xDoc.Descendants("listeners")
.Descendants("add")
.Where (d => d.Attribute("filename") != null )
.ToArray();
--- IMHO this is how I would rewrite the method, using linq and regex ---
var elements =
XDocument.Load(config);
.Descendants("listeners")
.Descendants("add")
.Where (node => node.Attribute("filename") != null )
.ToList();
return elements.Any() ? elements.Select (node => node.Attribute("filename").Value )
.Select (attrValue => Regex.Match(attrValue, "([^%]+)").Groups[1].Value)
.First ()
: string.Empty;