1. #21
    Sencha User
    Join Date
    Jan 2009
    Posts
    34
    Vote Rating
    0
    jerrel is on a distinguished road

      0  

    Default


    Hi Condor,

    Maybe you can also shine some light on my project.

    I need the parse this XML which is the output of a website

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
    <channel>
      <title>Yahoo! Weather - Sunnyvale, CA</title>
      <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
      <description>Yahoo! Weather for Sunnyvale, CA</description>
      <language>en-us</language>
      <lastBuildDate>Fri, 18 Dec 2009 9:38 am PST</lastBuildDate>
      <ttl>60</ttl>
      <yweather:location city="Sunnyvale" region="CA"   country="United States"/>
      <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
      <yweather:wind chill="50"   direction="0"   speed="0" />
      <yweather:atmosphere humidity="94"  visibility="3"  pressure="30.27"  rising="1" />
      <yweather:astronomy sunrise="7:17 am"   sunset="4:52 pm"/>
      <image>
        <title>Yahoo! Weather</title>
        <width>142</width>
        <height>18</height>
        <link>http://weather.yahoo.com</link>
        <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
      </image>
      <item>
        <title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
        <geo:lat>37.37</geo:lat>
        <geo:long>-122.04</geo:long>
        <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
        <pubDate>Fri, 18 Dec 2009 9:38 am PST</pubDate>
        <yweather:condition  text="Mostly Cloudy"  code="28"  temp="50"  date="Fri, 18 Dec 2009 9:38 am PST" />
        <description><![CDATA[
    <img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
    <b>Current Conditions:</b><br />
    Mostly Cloudy, 50 F<BR />
    <BR /><b>Forecast:</b><BR />
    Fri - Partly Cloudy. High: 62 Low: 49<br />
    Sat - Partly Cloudy. High: 65 Low: 49<br />
    <br />
    <a href="http://us.rd.yahoo.com/dailynews/rss...6_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
    (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
    ]]></description>
        <yweather:forecast day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30" />
        <yweather:forecast day="Sat" date="19 Dec 2009" low="49" high="65" text="Partly Cloudy" code="30" />
        <guid isPermaLink="false">USCA1116_2009_12_18_9_38_PST</guid>
      </item>
    </channel>
    </rss>

    For some strange reason, i cant display the title and link info in my div (id="temp")

    Here is my code:

    Code:
    var yahoostore = new Ext.data.Store({
       proxy: new Ext.data.HttpProxy({
                    url: 'my_backends/websmsbackend.php', 
                    method: 'POST'
                }),
                baseParams:{task: "YAHOORSSTEMP",feed:"http://weather.yahooapis.com/forecastrss?w=377227&u=c"},
      //url: 'http://weather.yahooapis.com/forecastrss?w=377227&u=c',
      
       
      reader: new Ext.data.XmlReader({
             record: 'channel',
             fields: [{name:'title', mapping:'@title'},{name:'link', mapping: '@link'}]
             })
             
             })
    yahoostore.on('load', function(store, records, options) {
    //alert('Info '+);
    var tpl = new Ext.XTemplate(
        /*'<tpl for=".">',*/
     '<tpl>',
        '<h1>{title}</h1>',
        '<h1>{link}</h1>',
        '</tpl>'
    );
    
    tpl.append(Ext.get("temp"), yahoostore.getRange());
    /*  tpl.append(Ext.getBody(), yahoostore.getRange()); */
        });
    yahoostore.load();
    //alert('Info '+yahoostore.getRange());
    Any idea what im doing wrong ?

  2. #22
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    Your mapping isn't '@title', it's simply 'title' (element instead of attribute).

  3. #23
    Sencha User
    Join Date
    Jan 2009
    Posts
    34
    Vote Rating
    0
    jerrel is on a distinguished road

      0  

    Default


    Condor,

    It worked thx, but only after spending exactly 24 hours on this issue.

    I did try title instead of @title, but still it didnt work.

    The data was not being formatted by the templ and displayed by in the div.

    I had no way to debug the store to see if the params where assigned a value.

    I could see however in FB the i received the xml from my script.

    I used a known inviorement (a grid) to display the data from the store, and it was then that i noticed that the data was in the store.

    Anyway, i spend these countless hours because i could not debug the store and temlate properly.

    The info is still not displayed in the div, but again I have no clue how to debug the store and templ.

    i would appreciate it if you could give me some pointers on these issues.

    Also do you see any thing wrong with this part of the code ?

    Code:
     
    var tpl = new Ext.XTemplate(
      '<tpl>',
        '<h1>{title}</h1>',
        '<h1>{link}</h1>',
        '</tpl>'
    );
     
    tpl.append(Ext.get("temp"), yahoostore.getRange());
    Thx

    Jerrel

  4. #24
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You should reread the API docs for XTemplate.
    Code:
    var tpl = new Ext.XTemplate(
      '<tpl for=".">',
        '<h1>{values.data.title}</h1>',
        '<h1>{values.data.link}</h1>',
      '</tpl>'
    );

  5. #25
    Sencha User ronivcp's Avatar
    Join Date
    Jan 2010
    Location
    Argentina
    Posts
    29
    Vote Rating
    0
    ronivcp is on a distinguished road

      0  

    Default


    I'm trying to do this: I have an xml file with information that I have to put into one or more charts. The thing is, if my xml file has only one chart tag (I have to make only one chart) my code works properly, but when I have to make more than one, my info gets mixed. So, what I wanted to ask is if there some way to do this, get one <chart>, process it, the next one, and so on.
    I think the problem may be the "valueReader" and "itemReader"


    Code:
    <chart title="first">
        <info>
            <Case id='1' color='blue'/>
            <Case id='2' color='green'/>
        </info>
        <data>
            <item value_x='Dec 25, 2008'>
                <value Case_id='1'>17</value>
                <value Case_id='2'>0</value>
            </item>
            <item value_x='Jan 29, 2009'>
                <value Case_id='1'>873</value>
                <value Case_id='2'>5</value>
            </item>
            <item value_x='Feb 16, 2009'>
                <value Case_id='1'>54</value>
                <value Case_id='2'>4</value>
            </item>
        </data>
    </chart>
    <chart title="sec">
    ...
    Code:
        var titleReader = new Ext.data.XmlReader({
            record: 'chart',
            idProperty: '@title',
            fields: [ {name: 'title', mapping: '@title', type: 'string'} ]
        });
        var caseReader = new Ext.data.XmlReader({
            record: 'Case',
            idProperty: '@id',
            fields: [ {name: 'id', mapping: '@id'},
                      {name: 'color', mapping: '@color', type: 'string'}]
        });
        var valueReader = new Ext.data.XmlReader({
            record: 'value',
            idProperty: '@serie_id',
            fields: [ {name: 'id', mapping: '@serie_id'},
                      {name: 'value', mapping: '/', type: 'int'} ]
        });
       this.itemReader = new Ext.data.XmlReader({
            record: 'item',
            idProperty: '@value_x',
            fields: [ {name: 'date', mapping: '@value_x'},
                      {name: 'values', mapping: '/', convert: function(v, n){
                        return valueReader.readRecords(n).records; } } ]
        });
        this.titleStore = new Ext.data.Store({ reader: titleReader });
        this.axesStore = new Ext.data.Store({ reader: axesReader });  
        this.seriesStore = new Ext.data.Store({ reader: seriesReader });
    ...
        obj.titleStore.loadData(obj.itemReader.xmlData);
        obj.caseStore.loadData(obj.itemReader.xmlData);
    Thanks in advance!

  6. #26
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    You have to make your record selector more specific, e.g.
    Code:
    record: 'chart[title=first] item'

  7. #27
    Sencha User ronivcp's Avatar
    Join Date
    Jan 2010
    Location
    Argentina
    Posts
    29
    Vote Rating
    0
    ronivcp is on a distinguished road

      0  

    Default


    Quote Originally Posted by Condor View Post
    You have to make your record selector more specific, e.g.
    Code:
    record: 'chart[title=first] item'
    Thanks a lot!!

  8. #28
    Sencha User ronivcp's Avatar
    Join Date
    Jan 2010
    Location
    Argentina
    Posts
    29
    Vote Rating
    0
    ronivcp is on a distinguished road

      0  

    Default


    I'm trying to get some information from an XML file but the thing is that I'm not interested in all of it, just the items with higher numbers (top 3) and also I have to make some conversions to that number, so as an example I have:

    <items total="55">
    <itemname="143c"number="1"></item>
    <itemname="1581c"number="1"></item>
    <itemname="21c"number="9"></item>
    <itemname="22c"number="19"></item>
    <itemname="23c"number="5"></item>
    <itemname="25c"number="14"></item>
    <itemname="3306c"number="3"></item>
    <itemname="41523c"number="3"></item>
    </items>

    How can I gent the ones with number 19,14 and 9 (top 3)?
    I have to show this as a percentage, I saw that with ext.data.record I can make a function and us it, but is not working with a XmlReader. I mean something like this:


    function numFormat(v, record){
    return (record.number * 1.8)
    }

    var rec = Ext.data.Record.create([
    {name: 'numFormat', convert: numFormat},
    {name: 'name', mapping: 'name''},
    {name: 'number', mapping: 'number'}
    ]);

    Is there a way to do this with a XmlReader?
    Thanks in advance!

  9. #29
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      0  

    Default


    1. You don't know what the top-3 is until you've read all items. So, the easiest solution is probably to read all items and remove/filter them afterwards.

    2. You want:
    Code:
    {name: 'numFormat', mapping: 'number', convert: function(v){return v * 1.8;}}

  10. #30
    Sencha User ronivcp's Avatar
    Join Date
    Jan 2010
    Location
    Argentina
    Posts
    29
    Vote Rating
    0
    ronivcp is on a distinguished road

      0  

    Default


    Thanks!
    But I don't know how to remove or filter the data. (I have to put this data on a grid.)
    Is there a way to get the top 3 from the store?
    Thanks again!