Weather::Weather(std::string city,std::string state, int day) { //Constructor ran every time we make a Weather object xml_data = ""; this->day = day; //its best to not re-download all of this redundant information every time you change weather //but the alternative would take longer to make/outside my skill std::cout << "City: "<< city << std::endl; std::cout << "State: "<< state << std::endl; std::replace(city.begin(),city.end(),' ','-'); std::replace(state.begin(),state.end(),' ','-'); std::string url_str = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22" + city + "%2C%20" + state + "%22)&format=xml&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; char* ustr = new char[url_str.size()]; strcpy(ustr, url_str.c_str()); getWeatherData(ustr); char* cstr = new char[xml_data.size() + 1]; strcpy (cstr, xml_data.c_str()); size_t size = xml_data.size() + 1; pugi::xml_parse_result result = doc.load_buffer_inplace(cstr, size); cond = getProperty("code"); if(day >= 0){ temp = getProperty("high"); } else { temp = getProperty("temp"); } delete[] cstr; delete[] ustr; }
void CWOBackendReq::ParseXML(pugi::xml_document& xmlFile) { pugi::xml_parse_result parseResult = xmlFile.load_buffer_inplace((void*)bodyStr_, bodyLen_); if(!parseResult) r3dError("Failed to parse server XML, error: %s", parseResult.description()); }