代码
 1 /************************************************************************/
 2 /* 作者:ericjhuang                                                     */
 3 /* 时间:2011年1月3日 15:34:38                                          */
 4 /************************************************************************/
 5 #ifndef _YAHOOWEATHER_H_
 6 #define _YAHOOWEATHER_H_
 7 
 8 typedef struct 
 9 {
10     //
11     int wind_chill;
12     int wind_direction;
13     float wind_speed;
14     //大气
15     int atmosphere_humidity;
16     int atmosphere_visibility;//可见度
17     float atmosphere_pressure;
18     int atmosphere_rising;
19     //日升日落
20     SYSTEMTIME  astronomy_sunrise;
21     SYSTEMTIME  astronomy_sunset;
22 }YahooWeatherData;
23 
24 class YahooWeather
25 {
26 public:
27     /************************************************************************/
28     /*  函数功能:根据城市名称获取天气信息                                  */
29     /************************************************************************/
30     YahooWeatherData getWeather(CString cityName);
31     /************************************************************************/
32     /*  函数功能:处理接收到的天气XML数据                                   */
33     /************************************************************************/
34     void processXMLData(CString data,YahooWeatherData* m_WeatherData);
35     /************************************************************************/
36     /* 函数功能:根据结点名称,获取节点属性字符串                           */
37     /************************************************************************/
38     CString getNodeProperties(CString data,CString nodeName);
39     /************************************************************************/
40     /* 函数功能:根据""字符串匹配返回字符串集                               */
41     /************************************************************************/
42     CStringArray* getNodeValues(CString nodeString);
43     /************************************************************************/
44     /* 函数功能:将字符串转换成日期                                         */
45     /************************************************************************/
46     BOOL StringToDate(LPCTSTR lpszValue, SYSTEMTIME &time);
47 
48 };
49 #endif
代码
 1 /************************************************************************/
 2 /* 作者:ericjhuang                                                     */
 3 /* 时间:2011年1月3日 15:34:38                                          */
 4 /************************************************************************/
 5 #ifndef _WEATHER_H_
 6 #define _WEATHER_H_
 7 
 8 typedef struct 
 9 {
10     CString conditiondata;
11     int temp_f;
12     int temp_c;//温度
13     float humiditydata;//湿度百分比
14     CString wind_conditiondata;//
15 }WeatherData;
16 
17 class GoogleWeather
18 {
19 public:
20     /************************************************************************/
21     /*  函数功能:根据城市名称获取天气信息                                  */
22     /************************************************************************/
23     WeatherData getWeather(CString cityName);
24     /************************************************************************/
25     /*  函数功能:处理接收到的天气XML数据                                   */
26     /************************************************************************/
27     void processXMLData(CString data,WeatherData* m_WeatherData);
28 };

 

 

先付上代码的头文件。元旦的时候,写了谷歌和雅虎的天气的API解析,主要是解析XML文件,原理很简单。

共享出来,供大家参考。