I have written the below code to handle accessing and parsing the data presented in XML format from our server room environmental monitor.
The plan is to call this class from a controller/view handling the "dashboard" on our Intranet page.
Is there any way I could optimize the class? should the methods really be static or would it be better to create an instance of the class and call the methods that way?
public class EnviromentialMonitorInterface
{
private static XmlDocument LoadInXML()
{
string environmentalMonitorUrl = "http://192.168.6.95/data.xml";
//string environmentalMonitorUrl = ConfigurationManager.AppSettings["WhiteListedDomainNames"];
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(environmentalMonitorUrl);
return xmlDoc;
}
public static double GetTemperature()
{
var extraction = LoadInXML().SelectSingleNode("//field[@key='TempC']").Attributes.GetNamedItem("value").Value;
double value = Convert.ToDouble(extraction);
return value;
}
public static int GetHumidity()
{
var extraction = LoadInXML().SelectSingleNode("//field[@key='Humidity']").Attributes.GetNamedItem("value").Value;
int value = Convert.ToInt32(extraction);
return value;
}
}