public static XmlElement GetSingleElement(this XmlDocument doc, string tagName)
{
var nodes = doc.GetElementsByTagName(tagName);
if (nodes.Count != 1)
{
throw new SmartAPIInternalException(
string.Format("Invalid number of {0} elements in XML reply from server. Expected: 1 actual: {1}",
tagName, nodes.Count));
}
return (XmlElement) nodes[0];
}