Hi, im doing an assignment where we have to read XML documents, put that data into a container of some kind and then draw it onto the screen. I was told by my teacher the other day that i should use an STL list. ive done that, and im pretty confident ive got all my XML data being stored in the list. The problem is i dont know how to get it back out. the information im storing is a 4 day forecast, each day containing the day's name, minimum temperature, maximum temperature and the weather condition (e.g sunny).
Here's a snippet of code to show you the process.
my xml reading function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
void XmlReader::ReadDoc(TiXmlDocument myDoc)
{
WeatherData* WeatherConditionsList = NULL;//creates a class type pointer
Conditions* pWeatherConditions = NULL; //creates a struct type pointer
//.......Skipping working down the nodes
while((pForecast_Conditions)!=NULL)
{
pWeatherConditions = new Conditions();
WeatherConditionsList = new WeatherData();
//an example of extracting one piece of data from the XML doc, in this case its the day
TiXmlElement *pDayofWeek = pForecast_Conditions->FirstChildElement("day_of_week");//element
Day = pDayofWeek->Attribute("data");//element data
pWeatherConditions->SetDayofWeek(Day);
std::cout << pWeatherConditions->m_DayofWeek<< std::endl;//This prints to the console fine.
//....
//once its gotten through the day it then stores pWeatherConditions into the list.
WeatherConditionsList->SetConditionsList(pWeatherConditions);
|
Ok then in my Weather.cpp the function definitions are as follows:
1 2 3 4 5 6 7 8 9 10
|
void Conditions::SetDayofWeek(const char* pDayofWeek)
{
if( m_DayofWeek )
{
delete m_DayofWeek;
}
m_DayofWeek = new char[sizeof(pDayofWeek)];
strcpy(m_DayofWeek,pDayofWeek);
}
|
1 2 3 4 5
|
void WeatherData::SetConditionsList(Conditions* conditions)
{
m_ConditionsList.begin();
m_ConditionsList.push_back(conditions);
}
|
So my problem is im not sure what the best way is to take this data and draw it to the screen. Ive also just tried printing it out to console like:
1 2 3 4 5 6 7 8 9 10
|
void WeatherData::GetConditionsList()
{
for(std::list<Conditions*>::iterator it = m_ConditionsList.begin(); it != m_ConditionsList.end(); ++it)
std::cout << it->m_DayofWeek << "---" << it-> m_MinTemp << "---" << it->m_MaxTemp << std::endl;
}
|
and i get an error "expression must have pointer-to-class type when I mouse over it (the iterator) in the std::cout << line.
My question is i need a way of getting the information from the list and knowing where to print it. i'm up for any suggestions such as creating multiple lists for each major city, making my struct hold Arrays so that each member variable can take it 4 days worth of data. i.e m_DayofWeek[4] so that i can store an entire xml doc's worth of data for Day in the one variable. I dont know. Suggestions on how to do this would be wonderful, thanks.