This is a migrated thread and some comments may be shown as answers.

Formatting the XML DS Results

3 Answers 99 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
sitefinitysteve asked on 21 Nov 2011, 03:39 PM
Ok, here's the xml
<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="Hamilton, ON"></city>
            <postal_code data="Hamilton,ON"></postal_code>
            <latitude_e6 data=""></latitude_e6>
            <longitude_e6 data=""></longitude_e6>
            <forecast_date data="2011-11-21"></forecast_date>
            <current_date_time data="2011-11-21 13:00:00 +0000"></current_date_time>
            <unit_system data="US"></unit_system>
        </forecast_information>
        <current_conditions>
            <condition data="Mostly Cloudy"></condition>
            <temp_f data="30"></temp_f>
            <temp_c data="-1"></temp_c>
            <humidity data="Humidity: 69%"></humidity>
            <icon data="/ig/images/weather/mostly_cloudy.gif"></icon>
            <wind_condition data="Wind: N at 10 mph"></wind_condition>
        </current_conditions>
        <forecast_conditions>
            <day_of_week data="Mon"></day_of_week>
            <low data="28"></low>
            <high data="41"></high>
            <icon data="/ig/images/weather/sunny.gif"></icon>
            <condition data="Clear"></condition>
        </forecast_conditions>
        <forecast_conditions>
            <day_of_week data="Tue"></day_of_week>
            <low data="37"></low>
            <high data="46"></high>
            <icon data="/ig/images/weather/chance_of_rain.gif"></icon>
            <condition data="Chance of Rain"></condition>
        </forecast_conditions>
        <forecast_conditions>
            <day_of_week data="Wed"></day_of_week>
            <low data="32"></low>
            <high data="50"></high>
            <icon data="/ig/images/weather/mostly_sunny.gif"></icon>
            <condition data="Mostly Sunny"></condition>
        </forecast_conditions>
        <forecast_conditions>
            <day_of_week data="Thu"></day_of_week>
            <low data="43"></low>
            <high data="50"></high>
            <icon data="/ig/images/weather/sunny.gif"></icon>
            <condition data="Clear"></condition>
        </forecast_conditions>
    </weather>
</xml_api_reply>

...and here's my schema
schema: {
            // specify the the schema is XML
            type: "xml",
            // the XML element which represents a single data record
            data: "/xml_api_reply/weather/forecast_conditions",
            // define the model - the object which will represent a single data record
            model: {
                fields: {
                    day_of_week: "day_of_week@data",
                    high: "low@data",
                    low: "high@data",
                    icon: "icon@data",
                    condition: "condition@data"
                }
            }
        },

...and the template
<ul id="weather-container">
 
</ul>
 
<script id="dashwidget-weather-template" type="text/x-kendo-template">
    <li>
        <div>#= day_of_week #</div>
        <div>#= condition #</div>
        <div>High: #= high #</div>
        <div>Low: #= low #</div>
    </li>
</script>


So I would like it structured like this:
<div>
  <div>CURRENT WEATHER</div>
  <ul>
      #repeater
          <li>DAILY WEATHER</li>
      #endrepeater
  </ul>
</div>

So I am clearly doing it WRONG :)  Since I'm only iterating over the weekday bits (so I wouldn't be able to get the current conditions).

How should I be re-working this?

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Nov 2011, 08:34 AM
Hi Steve,

 I am not really sure what you are after. Could you please elaborate? 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 24 Nov 2011, 11:32 AM
Sure (sorry :)

How do I define my schema such that I can get the XML into the below template

The documentation says to pick the node where it repeats, but I need data from multiple nodes in order to run the template
0
Atanas Korchev
Telerik team
answered on 28 Nov 2011, 08:47 AM
Hi Steve,

Are you trying to get <current_conditions> and <forecast_conditions> to map to the same field? If yes I am afraid this is not possible as you can specify only one tag. Perhaps you can use two datasources.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Atanas Korchev
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or