Getting weather data from Open Weather Map API I'm trying to make a simple app in C# that gets the weather data from http://openweathermap.org/api (OWM).

Here attached are two classes that I use to initialize WeatherData for selected City and to download and parse XML data from OWM API. I would like to know your opinion on the structure of the classes and the way I use them, because now I'm really not sure how should it work assuming that I would like to get/print more weather data in future.

I use them as follows:

WeatherData WarsawWeather = new WeatherData("Warsaw");
WarsawWeather.CheckWeather();
System.Console.WriteLine(WarsawWeather.Temp);


Classes:

using System.Net;
using System.Xml;

namespace WeatherApp
{
    class WeatherData
    {
        public WeatherData(string City)
        {
            city = City;
        }
        private string city;
        private float temp;
        private float tempMax;
        private float tempMin;

        public void CheckWeather()
        {
            WeatherAPI DataAPI = new WeatherAPI(City);
            temp = DataAPI.GetTemp();
        }

        public string City { get =&gt; city; set =&gt; city = value; }
        public float Temp { get =&gt; temp; set =&gt; temp = value; }
        public float TempMax { get =&gt; tempMax; set =&gt; tempMax = value; }
        public float TempMin { get =&gt; tempMin; set =&gt; tempMin = value; }
    }
    class WeatherAPI
    {
        public WeatherAPI(string city)
        {
            SetCurrentURL(city);
            xmlDocument = GetXML(CurrentURL);
        }

        public float GetTemp()
        {
            XmlNode temp_node = xmlDocument.SelectSingleNode("//temperature");
            XmlAttribute temp_value = temp_node.Attributes["value"];
            string temp_string = temp_value.Value;
            return float.Parse(temp_string);
        }

        private const string APIKEY = "API KEY HERE";
        private string CurrentURL;
        private XmlDocument xmlDocument;

        private void SetCurrentURL(string location)
        {
            CurrentURL = "http://api.openweathermap.org/data/2.5/weather?q=" 
                + location + "&amp;mode=xml&amp;units=metric&amp;APPID=" + APIKEY;
        }

        private XmlDocument GetXML(string CurrentURL)
        {
            using (WebClient client = new WebClient())
            {
                string xmlContent = client.DownloadString(CurrentURL);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(xmlContent);
                return xmlDocument;
            }
        }
    }
}


Example XML from OWM:

&lt;current&gt;
&lt;city id="756135" name="Warsaw"&gt;
&lt;coord lon="21.01" lat="52.23"/&gt;
&lt;country&gt;PL&lt;/country&gt;
&lt;sun rise="2016-12-27T06:45:16" set="2016-12-27T14:30:06"/&gt;
&lt;/city&gt;
&lt;temperature value="2" min="2" max="2" unit="metric"/&gt;
&lt;humidity value="80" unit="%"/&gt;
&lt;pressure value="1019" unit="hPa"/&gt;
&lt;wind&gt;
&lt;speed value="6.7" name="Moderate breeze"/&gt;
&lt;gusts/&gt;
&lt;direction value="310" code="NW" name="Northwest"/&gt;
&lt;/wind&gt;
&lt;clouds value="40" name="scattered clouds"/&gt;
&lt;visibility value="10000"/&gt;
&lt;precipitation mode="no"/&gt;
&lt;weather number="802" value="scattered clouds" icon="03n"/&gt;
&lt;lastupdate value="2016-12-27T20:00:00"/&gt;
&lt;/current&gt;
private float temp;
    private float tempMax;
    private float tempMin;



You should avoid abbreviating temperature. Temp is commonly used as an abbrevation for temporary and confuses here. In C# we don't usually use abbreviations. There are exceptions but they consider some well know ones like xml or html.




CurrentURL = "http://api.openweathermap.org/data/2.5/weather?q=" 
            + location + "&amp;mode=xml&amp;units=metric&amp;APPID=" + APIKEY;



You use some of the new C# 6 features already like the bodyless methods =&gt; so you might want to do the same for strings. The above line will become:

_currentURL = 
    $"http://api.openweathermap.org/data/2.5/weather?q={location}" + 
    $"&amp;mode=xml&amp;units=metric&amp;APPID={APIKEY}";




Using the var could make you code look much simpler. 

Consider this


    using (WebClient client = new WebClient())
    {
        string xmlContent = client.DownloadString(CurrentURL);
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xmlContent);
        return xmlDocument;
    }



vs that

    using (var webClient = new WebClient())
    {
        var xmlContent = webClient.DownloadString(CurrentURL);
        var xmlDocument = new XmlDocument();
        xmlDocument.LoadXml(xmlContent);
        return xmlDocument;
    }





XmlDocument



There's a newer and an easer way to work with xml. Try the XDocument out which is LINQ-capable. You'll like it. See XDocument or XmlDocument