public static string GetOptionalElementValue(this XContainer element, string localName, string namespaceName = null) { XElement child; if (String.IsNullOrEmpty(namespaceName)) { child = element.ElementsNoNamespace(localName).FirstOrDefault(); } else { child = element.Element(XName.Get(localName, namespaceName)); } return child != null ? child.Value : null; }