private static int FindTotal(XDocument doc) { var attribute = doc.Root.Attribute("TotalResults"); if (attribute != null) { try { return int.Parse(attribute.Value); } catch (Exception e) { // swallow the exception - not much can be done } } return 0; }