public static string ElementSafe(this XElement elem, string name) { if(elem == null || string.IsNullOrEmpty(name)) { return string.Empty; } var child = elem.Element(name); return child == null ? string.Empty : child.Value; }