public static void Main()
string xml1 = "<test><ex1>1/1/2014</ex1></test>";
string xml2 = "<test></test>";
string xml3 = "<test><ex1></ex1></test>";
Console.WriteLine("1: {0}", p.GetValue(xml1, "N/A"));
Console.WriteLine("2: {0}", p.GetValue(xml2, "N/A"));
Console.WriteLine("3: {0}", p.GetValue(xml3, "N/A"));
public string GetValue(string xml, string defaultValue)
var xmlDoc = new XmlDocument();
var node = xmlDoc.SelectSingleNode(".//ex1");
return (node == null || string.IsNullOrEmpty((node.InnerText ?? "").Trim()) ? defaultValue : node.InnerText.Trim());