Parsing XML with XmlListModel
Solved
QML and Qt Quick
-
Hello,
I need to parse XML like:
<response version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/taf1_2.xsd"> <request_index>19865992</request_index> <data_source name="tafs"/> <request type="retrieve"/> <errors/><warnings/> <time_taken_ms>8</time_taken_ms> <data num_results="1"> <TAF><raw_text>TAF LFAT 220800Z 2209/2218 VRB02KT 9999 SCT020 PROB30 2209/2211 BKN010 </raw_text> <station_id>LFAT</station_id> <issue_time>2019-10-22T08:00:00Z</issue_time> <bulletin_time>2019-10-22T08:00:00Z</bulletin_time> <valid_time_from>2019-10-22T09:00:00Z</valid_time_from> <valid_time_to>2019-10-22T18:00:00Z</valid_time_to> <latitude>50.52</latitude> <longitude>1.62</longitude> <elevation_m>14.0</elevation_m> <forecast> <fcst_time_from>2019-10-22T09:00:00Z</fcst_time_from> <fcst_time_to>2019-10-22T18:00:00Z</fcst_time_to> <wind_dir_degrees>0</wind_dir_degrees> <wind_speed_kt>2</wind_speed_kt> <visibility_statute_mi>6.21</visibility_statute_mi> <sky_condition sky_cover="SCT" cloud_base_ft_agl="2000"/> </forecast> TAF> </data> </response>
with QML code below:
XmlListModel { id: xmlModel source:"" query: "/response/data/TAF" XmlRole { name: "station_id"; query: "station_id/string()" } XmlRole { name: "fcst_time_from"; query: "forecast[1]/fcst_time_from/string()" } XmlRole { name: "fcst_time_to"; query: "forecast[1]/fcst_time_to/string()" } XmlRole { name: "wind_dir_degrees"; query: "forecast[1]/wind_dir_degrees/string()" } XmlRole { name: "wind_speed_kt"; query: "forecast[1]/wind_speed_kt/string()" } XmlRole { name: "visibility_statute_mi"; query: "forecast[1]/visibility_statute_mi/string()" } XmlRole { name: "sky_condition"; query: "forecast[1]/sky_condition/string()" } }
I read correctly all data except "sky_condition" because the beacon is not the same as other.
How should I decode <sky_condition sky_cover="SCT" cloud_base_ft_agl="2000"/> compare <visibility_statute_mi>6.21</visibility_statute_mi> ?
thank you very much for your help