Hello!
I'm trying to parse xml document:
Code:
<xml_api_reply version="1"> <weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0"> <forecast_information> <city data="Gdansk, Pomerania"/> <postal_code data="Gdansk,Poland"/> <latitude_e6 data=""/> <longitude_e6 data=""/> <forecast_date data="2010-12-09"/> <current_date_time data="2010-12-09 23:00:00 +0000"/> <unit_system data="SI"/> </forecast_information> <current_conditions> <condition data="Zachmurzenie"/> <temp_f data="30"/> <temp_c data="-1"/> <humidity data="Wilgotność: 86%"/> <icon data="/ig/images/weather/cloudy.gif"/> <wind_condition data="Wiatr: płn.-zach. z szybkością 26 km/h"/> </current_conditions> [...]
My code:
Code:
ByteArray newData = NetRepl->read(2048); out << newData << endl; QXmlStreamReader xmlStream(newData); while(!xmlStream.atEnd()) { xmlStream.readNext(); if(xmlStream.isStartElement()) { out << sec << endl; while (!xmlStream.isEndElement()) { xmlStream.readNext(); out << "***" << sec << endl; QXmlStreamAttributes attrs = xmlStream.attributes(); out << attrs.value("data").toString() << endl; } } }
And it sometimes returns "data" correctly, and sometimes it's empty:
Code:
xml_api_reply ***weather ***forecast_information ***city Gdansk, Pomerania //OK ***city postal_code ***postal_code latitude_e6 ***latitude_e6 longitude_e6 ***longitude_e6 forecast_date ***forecast_date current_date_time ***current_date_time unit_system ***unit_system current_conditions ***condition Zachmurzenie //OK ***condition temp_f ***temp_f temp_c ***temp_c humidity ***humidity icon ***icon wind_condition ***wind_condition
How should I do It correctly?
thanks in advance
best regards
Tomasz