|
-
August 27th, 2009, 08:12 AM
#16
Re: Reading XML documents in C#
try
Code:
high.SetValue(currentWeatherReport, Convert.ToInt32(forecast.Attributes["high"].Value), null);
-
August 27th, 2009, 09:13 AM
#17
Re: Reading XML documents in C#
Ok that works nicely, Thanks.
The last problem ive encountered is generating the URL for the image i use for each day.
Ive got the following code
Code:
PropertyInfo skycodeday = currentWeatherReport.GetType().GetProperty("SkyCode" + skycodenumber);
skycodeday.SetValue(currentWeatherReport, forecast.Attributes["SkyCode"].Value, null);
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
skycodenumber++;
so this works in terms of getting the correct SkyCode value and it stores them with no problem. But i now need to generate a URL based on the day number
so it generates a URL which is : skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif"
so this now needs to be something like currentWeatherReport.SkyCode + skycodenumber + ".gif" but im not sure.
also it will then need to save as SkyImage1-5 as before, how might i do this, in the same way as the others?
-
August 27th, 2009, 10:34 AM
#18
Re: Reading XML documents in C#
just for the hell of it, if you are using .Net 3.5, you can use LINQ-To-XML..
Code:
XDocument doc = XDocument.Load("http://weather.service.msn.com/data.aspx?src=vista&wealocations=wc:USWA0367");
var query = from e in doc.Root.Descendants("weather")
select new WeatherReport
{
CurrentTemperature = int.Parse(e.Element("current").Attribute("temperature").Value),
FeelsLikeTemperature = int.Parse(e.Element("current").Attribute("feelslike").Value),
Day1 = e.Descendants("forecast").Attributes("day").First().Value,
Day3 = e.Descendants("forecast").Attributes("day").Skip(2).First().Value,
Day4 = e.Descendants("forecast").Attributes("day").Skip(3).First().Value,
};
-
August 27th, 2009, 02:07 PM
#19
Re: Reading XML documents in C#
Thanks for that, i may look into that after ive finished.
If anyone has any ideas on my other problem let me know
-
August 28th, 2009, 03:13 AM
#20
Re: Reading XML documents in C#
Anyone any ideas on the below?
 Originally Posted by InsyteMedia
Ok that works nicely, Thanks.
The last problem ive encountered is generating the URL for the image i use for each day.
Ive got the following code
Code:
PropertyInfo skycodeday = currentWeatherReport.GetType().GetProperty("SkyCode" + skycodenumber);
skycodeday.SetValue(currentWeatherReport, forecast.Attributes["SkyCode"].Value, null);
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
skycodenumber++;
so this works in terms of getting the correct SkyCode value and it stores them with no problem. But i now need to generate a URL based on the day number
so it generates a URL which is : skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif"
so this now needs to be something like currentWeatherReport.SkyCode + skycodenumber + ".gif" but im not sure.
also it will then need to save as SkyImage1-5 as before, how might i do this, in the same way as the others?
-
August 28th, 2009, 09:01 PM
#21
Re: Reading XML documents in C#
Show us the results of:
What you HAVE
What you WANT
and
What the current strings are.
-
September 2nd, 2009, 08:03 AM
#22
Re: Reading XML documents in C#
Ok, so far when the refresh button is used the following code is run
Code:
public WeatherReport.WeatherReport GetWeatherReport(string location)
{
WeatherReport.WeatherReport currentWeatherReport = new WeatherReport.WeatherReport();
// URL corresponding to the MSN REST Web Service - see how the locationCode is passed in parameter to this URL.
// The XMLTextReader opens up the URL and receives the XML returned by the server
// http://weather.service.msn.com/data.aspx?src=vista&wealocations=wc:USWA0367
string feedUrl = "http://weather.service.msn.com/data.aspx?src=vista&wealocations=" + location;
XmlTextReader reader = new XmlTextReader(feedUrl);
bool firstForecastDone = false;
string skyImagesRelativeUrl = "Images/";
int MaxTemp, MinTemp, CurrentTemp, FeelsLike, Humidity, SkyCode;
try
{
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "weather"))
{
reader.MoveToAttribute("weatherlocationname");
currentWeatherReport.Location = reader.Value;
reader.MoveToAttribute("lat");
currentWeatherReport.Lattitude = reader.Value;
reader.MoveToAttribute("long");
currentWeatherReport.Longitude = reader.Value;
}
else if ((reader.NodeType == XmlNodeType.Element) && ((reader.Name == "forecast")
&& (firstForecastDone == false)))
{
firstForecastDone = true;
reader.MoveToAttribute("high");
int.TryParse(reader.Value, out MaxTemp);
currentWeatherReport.MaxTemperatureForecast = MaxTemp;
reader.MoveToAttribute("low");
int.TryParse(reader.Value, out MinTemp);
currentWeatherReport.MinTemperatureForecast = MinTemp;
}
else if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "current"))
{
reader.MoveToAttribute("temperature");
int.TryParse(reader.Value, out CurrentTemp);
currentWeatherReport.CurrentTemperature = CurrentTemp;
reader.MoveToAttribute("feelslike");
int.TryParse(reader.Value, out FeelsLike);
currentWeatherReport.FeelsLikeTemperature = FeelsLike;
reader.MoveToAttribute("humidity");
int.TryParse(reader.Value, out Humidity);
currentWeatherReport.Humidity = Humidity;
reader.MoveToAttribute("skytext");
currentWeatherReport.SkyText = reader.Value;
reader.MoveToAttribute("skycode");
int.TryParse(reader.Value, out SkyCode);
currentWeatherReport.SkyCode = SkyCode;
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
reader.MoveToAttribute("observationtime");
char[] splitter = ":".ToCharArray();
string[] hourMinuteSecond = reader.Value.Split(splitter);
int hour, minute, second;
int.TryParse(hourMinuteSecond[0], out hour);
int.TryParse(hourMinuteSecond[1], out minute);
int.TryParse(hourMinuteSecond[2], out second);
reader.MoveToAttribute("date");
splitter = "-".ToCharArray();
string[] yearMonthDay = reader.Value.Split(splitter);
int year, month, day;
int.TryParse(yearMonthDay[0], out year);
int.TryParse(yearMonthDay[1], out month);
int.TryParse(yearMonthDay[2], out day);
currentWeatherReport.LastUpdate = new DateTime(year, month, day, hour, minute, second);
reader.MoveToAttribute("winddisplay");
currentWeatherReport.WindDisplay = reader.Value;
reader.MoveToAttribute("observationpoint");
currentWeatherReport.Observation = reader.Value;
}
XmlDocument doc = new XmlDocument();
doc.Load(feedUrl);
XmlNodeList forecast_list = doc.DocumentElement.SelectNodes("weather/forecast");
int daynumber = 1;
int precipnumber = 1;
int skytextnumber = 1;
int minTempnumber = 1;
int maxTempnumber = 1;
foreach (XmlNode forecast in forecast_list)
{
PropertyInfo day = currentWeatherReport.GetType().GetProperty("Day" + daynumber);
day.SetValue(currentWeatherReport, forecast.Attributes["day"].Value, null);
daynumber++;
PropertyInfo skytextday = currentWeatherReport.GetType().GetProperty("SkyText" + skytextnumber);
skytextday.SetValue(currentWeatherReport, forecast.Attributes["skytextday"].Value, null);
skytextnumber++;
PropertyInfo precip = currentWeatherReport.GetType().GetProperty("Precipitation" + precipnumber);
precip.SetValue(currentWeatherReport, forecast.Attributes["precip"].Value, null);
precipnumber++;
PropertyInfo high = currentWeatherReport.GetType().GetProperty("MaxTemperatureForecast" + maxTempnumber);
high.SetValue(currentWeatherReport, Convert.ToInt32(forecast.Attributes["high"].Value), null);
maxTempnumber++;
PropertyInfo low = currentWeatherReport.GetType().GetProperty("MinTemperatureForecast" + minTempnumber);
low.SetValue(currentWeatherReport, Convert.ToInt32(forecast.Attributes["low"].Value), null);
minTempnumber++;
}
}
return currentWeatherReport;
}
catch (Exception ex)
{
throw ex;
}
}
This stores all of the values it gets in here:
Code:
public class WeatherReport
{
private int currentTempValue;
public int CurrentTemperature {
get
{
return currentTempValue;
}
set
{
currentTempValue = value;
}
}
private int feelsLikeTemperatureValue;
public int FeelsLikeTemperature
{
get
{
return feelsLikeTemperatureValue;
}
set
{
feelsLikeTemperatureValue = value;
}
}
private int humidityValue;
public int Humidity
{
get
{
return humidityValue;
}
set
{
humidityValue = value;
}
}
private DateTime lastUpdateValue;
public DateTime LastUpdate
{
get
{
return lastUpdateValue;
}
set
{
lastUpdateValue = value;
}
}
private string locationValue;
public string Location
{
get
{
return locationValue;
}
set
{
locationValue = value;
}
}
private int skyCodeValue;
public int SkyCode
{
get
{
return skyCodeValue;
}
set
{
skyCodeValue = value;
}
}
private int skyCode1Value;
public int SkyCode1
{
get
{
return skyCode1Value;
}
set
{
skyCode1Value = value;
}
}
private int skyCode2Value;
public int SkyCode2
{
get
{
return skyCode2Value;
}
set
{
skyCode2Value = value;
}
}
private int skyCode3Value;
public int SkyCode3
{
get
{
return skyCode3Value;
}
set
{
skyCode3Value = value;
}
}
private int skyCode4Value;
public int SkyCode4
{
get
{
return skyCode4Value;
}
set
{
skyCode4Value = value;
}
}
private string skyTextValue;
public string SkyText
{
get
{
return skyTextValue;
}
set
{
skyTextValue = value;
}
}
private string SkyText1Value;
public string SkyText1
{
get
{
return SkyText1Value;
}
set
{
SkyText1Value = value;
}
}
private string SkyText2Value;
public string SkyText2
{
get
{
return SkyText2Value;
}
set
{
SkyText2Value = value;
}
}
private string SkyText3Value;
public string SkyText3
{
get
{
return SkyText3Value;
}
set
{
SkyText3Value = value;
}
}
private string SkyText4Value;
public string SkyText4
{
get
{
return SkyText4Value;
}
set
{
SkyText4Value = value;
}
}
private string SkyText5Value;
public string SkyText5
{
get
{
return SkyText5Value;
}
set
{
SkyText5Value = value;
}
}
private Bitmap skyImageValue;
public Bitmap SkyImage
{
get
{
return skyImageValue;
}
set
{
skyImageValue = value;
}
}
private int minTemperatureForecastValue;
public int MinTemperatureForecast
{
get
{
return minTemperatureForecastValue;
}
set
{
minTemperatureForecastValue = value;
}
}
private int maxTemperatureForecastValue;
public int MaxTemperatureForecast
{
get
{
return maxTemperatureForecastValue;
}
set
{
maxTemperatureForecastValue = value;
}
}
private string locationCodeValue;
public string LocationCodeValue
{
get
{
return locationCodeValue;
}
set
{
locationCodeValue = value;
}
}
private string WindDisplayValue;
public string WindDisplay
{
get
{
return WindDisplayValue;
}
set
{
WindDisplayValue = value;
}
}
private string LattitudeValue;
public string Lattitude
{
get
{
return LattitudeValue;
}
set
{
LattitudeValue = value;
}
}
private string LongitudeValue;
public string Longitude
{
get
{
return LongitudeValue;
}
set
{
LongitudeValue = value;
}
}
private string ObservationValue;
public string Observation
{
get
{
return ObservationValue;
}
set
{
ObservationValue = value;
}
}
private string Day1Value;
public string Day1
{
get
{
return Day1Value;
}
set
{
Day1Value = value;
}
}
private string Day2Value;
public string Day2
{
get
{
return Day2Value;
}
set
{
Day2Value = value;
}
}
private string Day3Value;
public string Day3
{
get
{
return Day3Value;
}
set
{
Day3Value = value;
}
}
private string Day4Value;
public string Day4
{
get
{
return Day4Value;
}
set
{
Day4Value = value;
}
}
private string Day5Value;
public string Day5
{
get
{
return Day5Value;
}
set
{
Day5Value = value;
}
}
private Bitmap skyImage1Value;
public Bitmap SkyImage1
{
get
{
return skyImage1Value;
}
set
{
skyImage1Value = value;
}
}
private Bitmap skyImage2Value;
public Bitmap SkyImage2
{
get
{
return skyImage2Value;
}
set
{
skyImage2Value = value;
}
}
private Bitmap skyImage3Value;
public Bitmap SkyImage3
{
get
{
return skyImage3Value;
}
set
{
skyImage3Value = value;
}
}
private Bitmap skyImage4Value;
public Bitmap SkyImage4
{
get
{
return skyImage4Value;
}
set
{
skyImage4Value = value;
}
}
private Bitmap skyImage5Value;
public Bitmap SkyImage5
{
get
{
return skyImage5Value;
}
set
{
skyImage5Value = value;
}
}
private List<ForeCast> foreCast_list = new List<ForeCast>();
public List<ForeCast> ForeCast_list
{
get
{
return foreCast_list;
}
set
{
foreCast_list = value;
}
}
}
Now for the current day the following code is used to get the skycode and the image:
Code:
reader.MoveToAttribute("skycode");
int.TryParse(reader.Value, out SkyCode);
currentWeatherReport.SkyCode = SkyCode;
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
this stores the skycode and add the URL to the images folder to it so in the end it would say \images\12.gif and that would be used to get the image.
im now doing a forecast from 4 additional days and with the other attributes ive saved them as attribute1, attribute2..., not the best way i know but its the method ive done.
i now want to uses the same kind of code as above but instead of saving it as SkyImage i want it to be SkyImage1, SkyImage2......
-
September 3rd, 2009, 06:30 PM
#23
Re: Reading XML documents in C#
I ve tried this for something similar I am doing is and even though it works perfect I wanted to was there a more efficient way of achieving the same result? I was ways told that a lot of if and else statements isn't good to do.
 Originally Posted by InsyteMedia
Ok, so far when the refresh button is used the following code is run
Code:
public WeatherReport.WeatherReport GetWeatherReport(string location)
{
WeatherReport.WeatherReport currentWeatherReport = new WeatherReport.WeatherReport();
// URL corresponding to the MSN REST Web Service - see how the locationCode is passed in parameter to this URL.
// The XMLTextReader opens up the URL and receives the XML returned by the server
// http://weather.service.msn.com/data.aspx?src=vista&wealocations=wc:USWA0367
string feedUrl = "http://weather.service.msn.com/data.aspx?src=vista&wealocations=" + location;
XmlTextReader reader = new XmlTextReader(feedUrl);
bool firstForecastDone = false;
string skyImagesRelativeUrl = "Images/";
int MaxTemp, MinTemp, CurrentTemp, FeelsLike, Humidity, SkyCode;
try
{
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "weather"))
{
reader.MoveToAttribute("weatherlocationname");
currentWeatherReport.Location = reader.Value;
reader.MoveToAttribute("lat");
currentWeatherReport.Lattitude = reader.Value;
reader.MoveToAttribute("long");
currentWeatherReport.Longitude = reader.Value;
}
else if ((reader.NodeType == XmlNodeType.Element) && ((reader.Name == "forecast")
&& (firstForecastDone == false)))
{
firstForecastDone = true;
reader.MoveToAttribute("high");
int.TryParse(reader.Value, out MaxTemp);
currentWeatherReport.MaxTemperatureForecast = MaxTemp;
reader.MoveToAttribute("low");
int.TryParse(reader.Value, out MinTemp);
currentWeatherReport.MinTemperatureForecast = MinTemp;
}
else if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "current"))
{
reader.MoveToAttribute("temperature");
int.TryParse(reader.Value, out CurrentTemp);
currentWeatherReport.CurrentTemperature = CurrentTemp;
reader.MoveToAttribute("feelslike");
int.TryParse(reader.Value, out FeelsLike);
currentWeatherReport.FeelsLikeTemperature = FeelsLike;
reader.MoveToAttribute("humidity");
int.TryParse(reader.Value, out Humidity);
currentWeatherReport.Humidity = Humidity;
reader.MoveToAttribute("skytext");
currentWeatherReport.SkyText = reader.Value;
reader.MoveToAttribute("skycode");
int.TryParse(reader.Value, out SkyCode);
currentWeatherReport.SkyCode = SkyCode;
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
reader.MoveToAttribute("observationtime");
char[] splitter = ":".ToCharArray();
string[] hourMinuteSecond = reader.Value.Split(splitter);
int hour, minute, second;
int.TryParse(hourMinuteSecond[0], out hour);
int.TryParse(hourMinuteSecond[1], out minute);
int.TryParse(hourMinuteSecond[2], out second);
reader.MoveToAttribute("date");
splitter = "-".ToCharArray();
string[] yearMonthDay = reader.Value.Split(splitter);
int year, month, day;
int.TryParse(yearMonthDay[0], out year);
int.TryParse(yearMonthDay[1], out month);
int.TryParse(yearMonthDay[2], out day);
currentWeatherReport.LastUpdate = new DateTime(year, month, day, hour, minute, second);
reader.MoveToAttribute("winddisplay");
currentWeatherReport.WindDisplay = reader.Value;
reader.MoveToAttribute("observationpoint");
currentWeatherReport.Observation = reader.Value;
}
XmlDocument doc = new XmlDocument();
doc.Load(feedUrl);
XmlNodeList forecast_list = doc.DocumentElement.SelectNodes("weather/forecast");
int daynumber = 1;
int precipnumber = 1;
int skytextnumber = 1;
int minTempnumber = 1;
int maxTempnumber = 1;
foreach (XmlNode forecast in forecast_list)
{
PropertyInfo day = currentWeatherReport.GetType().GetProperty("Day" + daynumber);
day.SetValue(currentWeatherReport, forecast.Attributes["day"].Value, null);
daynumber++;
PropertyInfo skytextday = currentWeatherReport.GetType().GetProperty("SkyText" + skytextnumber);
skytextday.SetValue(currentWeatherReport, forecast.Attributes["skytextday"].Value, null);
skytextnumber++;
PropertyInfo precip = currentWeatherReport.GetType().GetProperty("Precipitation" + precipnumber);
precip.SetValue(currentWeatherReport, forecast.Attributes["precip"].Value, null);
precipnumber++;
PropertyInfo high = currentWeatherReport.GetType().GetProperty("MaxTemperatureForecast" + maxTempnumber);
high.SetValue(currentWeatherReport, Convert.ToInt32(forecast.Attributes["high"].Value), null);
maxTempnumber++;
PropertyInfo low = currentWeatherReport.GetType().GetProperty("MinTemperatureForecast" + minTempnumber);
low.SetValue(currentWeatherReport, Convert.ToInt32(forecast.Attributes["low"].Value), null);
minTempnumber++;
}
}
return currentWeatherReport;
}
catch (Exception ex)
{
throw ex;
}
}
This stores all of the values it gets in here:
Code:
public class WeatherReport
{
private int currentTempValue;
public int CurrentTemperature {
get
{
return currentTempValue;
}
set
{
currentTempValue = value;
}
}
private int feelsLikeTemperatureValue;
public int FeelsLikeTemperature
{
get
{
return feelsLikeTemperatureValue;
}
set
{
feelsLikeTemperatureValue = value;
}
}
private int humidityValue;
public int Humidity
{
get
{
return humidityValue;
}
set
{
humidityValue = value;
}
}
private DateTime lastUpdateValue;
public DateTime LastUpdate
{
get
{
return lastUpdateValue;
}
set
{
lastUpdateValue = value;
}
}
private string locationValue;
public string Location
{
get
{
return locationValue;
}
set
{
locationValue = value;
}
}
private int skyCodeValue;
public int SkyCode
{
get
{
return skyCodeValue;
}
set
{
skyCodeValue = value;
}
}
private int skyCode1Value;
public int SkyCode1
{
get
{
return skyCode1Value;
}
set
{
skyCode1Value = value;
}
}
private int skyCode2Value;
public int SkyCode2
{
get
{
return skyCode2Value;
}
set
{
skyCode2Value = value;
}
}
private int skyCode3Value;
public int SkyCode3
{
get
{
return skyCode3Value;
}
set
{
skyCode3Value = value;
}
}
private int skyCode4Value;
public int SkyCode4
{
get
{
return skyCode4Value;
}
set
{
skyCode4Value = value;
}
}
private string skyTextValue;
public string SkyText
{
get
{
return skyTextValue;
}
set
{
skyTextValue = value;
}
}
private string SkyText1Value;
public string SkyText1
{
get
{
return SkyText1Value;
}
set
{
SkyText1Value = value;
}
}
private string SkyText2Value;
public string SkyText2
{
get
{
return SkyText2Value;
}
set
{
SkyText2Value = value;
}
}
private string SkyText3Value;
public string SkyText3
{
get
{
return SkyText3Value;
}
set
{
SkyText3Value = value;
}
}
private string SkyText4Value;
public string SkyText4
{
get
{
return SkyText4Value;
}
set
{
SkyText4Value = value;
}
}
private string SkyText5Value;
public string SkyText5
{
get
{
return SkyText5Value;
}
set
{
SkyText5Value = value;
}
}
private Bitmap skyImageValue;
public Bitmap SkyImage
{
get
{
return skyImageValue;
}
set
{
skyImageValue = value;
}
}
private int minTemperatureForecastValue;
public int MinTemperatureForecast
{
get
{
return minTemperatureForecastValue;
}
set
{
minTemperatureForecastValue = value;
}
}
private int maxTemperatureForecastValue;
public int MaxTemperatureForecast
{
get
{
return maxTemperatureForecastValue;
}
set
{
maxTemperatureForecastValue = value;
}
}
private string locationCodeValue;
public string LocationCodeValue
{
get
{
return locationCodeValue;
}
set
{
locationCodeValue = value;
}
}
private string WindDisplayValue;
public string WindDisplay
{
get
{
return WindDisplayValue;
}
set
{
WindDisplayValue = value;
}
}
private string LattitudeValue;
public string Lattitude
{
get
{
return LattitudeValue;
}
set
{
LattitudeValue = value;
}
}
private string LongitudeValue;
public string Longitude
{
get
{
return LongitudeValue;
}
set
{
LongitudeValue = value;
}
}
private string ObservationValue;
public string Observation
{
get
{
return ObservationValue;
}
set
{
ObservationValue = value;
}
}
private string Day1Value;
public string Day1
{
get
{
return Day1Value;
}
set
{
Day1Value = value;
}
}
private string Day2Value;
public string Day2
{
get
{
return Day2Value;
}
set
{
Day2Value = value;
}
}
private string Day3Value;
public string Day3
{
get
{
return Day3Value;
}
set
{
Day3Value = value;
}
}
private string Day4Value;
public string Day4
{
get
{
return Day4Value;
}
set
{
Day4Value = value;
}
}
private string Day5Value;
public string Day5
{
get
{
return Day5Value;
}
set
{
Day5Value = value;
}
}
private Bitmap skyImage1Value;
public Bitmap SkyImage1
{
get
{
return skyImage1Value;
}
set
{
skyImage1Value = value;
}
}
private Bitmap skyImage2Value;
public Bitmap SkyImage2
{
get
{
return skyImage2Value;
}
set
{
skyImage2Value = value;
}
}
private Bitmap skyImage3Value;
public Bitmap SkyImage3
{
get
{
return skyImage3Value;
}
set
{
skyImage3Value = value;
}
}
private Bitmap skyImage4Value;
public Bitmap SkyImage4
{
get
{
return skyImage4Value;
}
set
{
skyImage4Value = value;
}
}
private Bitmap skyImage5Value;
public Bitmap SkyImage5
{
get
{
return skyImage5Value;
}
set
{
skyImage5Value = value;
}
}
private List<ForeCast> foreCast_list = new List<ForeCast>();
public List<ForeCast> ForeCast_list
{
get
{
return foreCast_list;
}
set
{
foreCast_list = value;
}
}
}
Now for the current day the following code is used to get the skycode and the image:
Code:
reader.MoveToAttribute("skycode");
int.TryParse(reader.Value, out SkyCode);
currentWeatherReport.SkyCode = SkyCode;
string fileName = skyImagesRelativeUrl + currentWeatherReport.SkyCode + ".gif";
currentWeatherReport.SkyImage = new Bitmap(fileName);
this stores the skycode and add the URL to the images folder to it so in the end it would say \images\12.gif and that would be used to get the image.
im now doing a forecast from 4 additional days and with the other attributes ive saved them as attribute1, attribute2..., not the best way i know but its the method ive done.
i now want to uses the same kind of code as above but instead of saving it as SkyImage i want it to be SkyImage1, SkyImage2......
-
September 3rd, 2009, 09:20 PM
#24
Re: Reading XML documents in C#
That isn't an example of a lot of IF statements. That's because you are using ELSE IF with each one. This groups them into one SELECT statement, and only one executes each time.
-
September 5th, 2009, 07:39 PM
#25
Re: Reading XML documents in C#
so any ideas regarding my problem?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|