}// end of method ProcessData public static bool SaveCurrentWeatherXML(string providerName, DateTime datePublished, string cityName, string countryName, string currentConditions, string currentTemperature, string currentFeelsLikeTemperture, string currentHigh, string currentLow, string currentWindSpeed, string currentWindDirection, string currentHumidity, string sunriseTime, string sunsetTime, List <FiveDayForecast> fiveDayForecast) { string weatherDataDirectory = WeatherLionMain.DATA_DIRECTORY_PATH; TimeZone localZone = TimeZone.CurrentTimeZone; string tzAbbr = UtilityMethod.ReplaceAll(localZone.DaylightName, "[a-z]", "").Replace(" ", ""); // create all necessary files if they are not present if (!Directory.Exists(weatherDataDirectory)) { Directory.CreateDirectory(weatherDataDirectory); }// end of if block try { XmlWriter writer; XmlDocument xmlDoc = new XmlDocument(); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = ("\t"), CloseOutput = true, OmitXmlDeclaration = false }; // create a new file each time writer = XmlWriter.Create(previousWeatherDataXML, settings); // Root XmlElement writer.WriteStartElement("WeatherData"); // Provider Details writer.WriteStartElement("Provider"); writer.WriteElementString("Name", providerName); writer.WriteElementString("Date", string.Format("{0:ddd MMM dd HH:mm:ss} {1} {0:yyyy}", datePublished, tzAbbr)); writer.WriteEndElement(); // Location Readings writer.WriteStartElement("Location"); writer.WriteElementString("City", cityName); writer.WriteElementString("Country", countryName); writer.WriteEndElement(); // Atmospheric Readings writer.WriteStartElement("Atmosphere"); writer.WriteElementString("Humidity", currentHumidity); writer.WriteEndElement(); // Wind Readings writer.WriteStartElement("Wind"); writer.WriteElementString("WindSpeed", currentWindSpeed); writer.WriteElementString("WindDirection", currentWindDirection); writer.WriteEndElement(); // Astronomy readings writer.WriteStartElement("Astronomy"); writer.WriteElementString("Sunrise", sunriseTime); writer.WriteElementString("Sunset", sunsetTime); writer.WriteEndElement(); // Current Weather writer.WriteStartElement("Current"); writer.WriteElementString("Condition", UtilityMethod.ToProperCase(currentConditions)); writer.WriteElementString("Temperature", currentTemperature); writer.WriteElementString("FeelsLike", currentFeelsLikeTemperture); writer.WriteElementString("HighTemperature", currentHigh); writer.WriteElementString("LowTemperature", currentLow); writer.WriteEndElement(); // list of forecast data writer.WriteStartElement("DailyForecast"); // Five Day Forecast foreach (FiveDayForecast forecast in fiveDayForecast) { writer.WriteStartElement("DayForecast"); writer.WriteElementString("Date", string.Format("{0:ddd MMM dd hh:mm:ss} {1} {0:yyyy}", forecast.forecastDate, tzAbbr)); writer.WriteElementString("Condition", UtilityMethod.ToProperCase(forecast.forecastCondition)); writer.WriteElementString("LowTemperature", forecast.forecastLowTemp); writer.WriteElementString("HighTemperature", forecast.forecastHighTemp); writer.WriteEndElement(); }// end of for each loop writer.WriteEndElement(); // close the root element writer.WriteEndElement(); writer.Flush(); writer.Close(); UtilityMethod.LogMessage(UtilityMethod.LogLevel.INFO, providerName + "'s weather data was stored locally!", "WeatherDataXMLService::SaveCurrentWeatherXML"); }// end of try block catch (FileNotFoundException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::SaveCurrentWeatherXML [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); }// end of catch block catch (IOException e) { UtilityMethod.LogMessage(UtilityMethod.LogLevel.SEVERE, e.Message, $"{TAG}::SaveCurrentWeatherXML [line: {UtilityMethod.GetExceptionLineNumber(e)}]"); }// end of catch block return(true); }// end of method SaveCurrentWeatherXML