-1

How to fetch live data from stcok market using rss feed live using Yahoo Query language . And using this I'm getting data from the market like below :

<results>
        <item>
            <title><![CDATA[SENSEX : 20850.74 * 451.32 (2.21 %)]]></title>
            <link/>
            <pubDate>11/18/2013 4:00:00 PM</pubDate>
            <author>BSEIndia</author>
            <guid/>
        </item>
    </results>

Now using Java script I am displaying the data in UI , the javascript is below:

function SensexRSS(o) {
        var items = o.query.results.item;
        var output = '';            
        var title = items.title;     
        output += "BSE" + " " + title;
        }
        // Place news stories in div tag  
        document.getElementById('bsesensex').innerHTML = output;
    }

As a result the UI shows the data like : BseSensex : 20850.74 * 451.32 (2.21 %)

Now I want to split this text and remove the * and () symbols and try to show color like green(for Up market) and red (for down market)

Can anyone tell me please how tot format or split the data from ![CDATA[...] that is above inside ....

D S
  • 258
  • 9
  • 25

2 Answers2

1

For split str.split("YOUR DELEMETER ");
For remove / replace str.replace("*"," ");
For colour: str.fontcolor("green");

Note : fontcolor() method returns the string embedded in the <font> tag. The tag is not supported in HTML5. Use CSS instead.

pratim_b
  • 1,160
  • 10
  • 29
  • One question to you I know this is not right question but asking you to gain some knowledge, though data is come from 3rd party so I don't know it is up or down , so how to use some condition if market is up then green or red from this ![CDATA[SENSEX : 20850.74 * 451.32 (2.21 %)] – D S Nov 18 '13 at 12:00
  • How do you consider what is up or down?? If it depends upon previous value, then storing it in database and comparing later on might help – pratim_b Nov 18 '13 at 12:04
  • No dear,if Is tore it some where suppose I have store today's value 451.32 and put some condition if tomorrow the value is above of 451.32 then show green Image else show Red, and suppose the value is 400 as a result this should be red but the next day it becomes 410 then ? It should show the green Image but the value is store 451.32 so it will show red that is incorrect – D S Nov 18 '13 at 12:28
  • No always update with last days value. You update the value of 451.32 with 400. so next day when you compare, you will compare with 400 and not 451. So it will be green as 410 is greater then 400 – pratim_b Nov 18 '13 at 12:30
  • It is very difficult to me to update everyday,I can't do it.Have you any knowledge how other sites are showing share related data live.I am getting this data from BSE rss feed but they are providing this like unformatted under ![CDATA[...] . This becomes difficult to me to make it attractive to viewrs. – D S Nov 18 '13 at 12:38
  • Well, without storing the data.. you need to have last days data from somewhere. If you can get it , then don't store it. Anyways what problem you have on updating everyday? You dont need to go and manually update. Add some lines of code to update database – pratim_b Nov 18 '13 at 12:40
  • OK , I have done this anyway thanks rookieB a lots for helping me , through your guidance I can able to do this, I have also write an article for this , pl have a look and also leave your comments there,Thanks you agian : http://silverlightpractice.blogspot.in/2013/11/how-to-show-live-bse-sensex-data-in.html – D S Nov 21 '13 at 20:07
0
  1. To display "up" and "down" status of market you need two images a green up arrow image and a red down arrow image.
  2. To display proper data, you need to write either regular expression to remove * and () symbols or you can use string replacement techniques to get the text in format you need.
  3. Then use (1) and (2) to generate a HTML markup per your needs.

You need to tell what format you are expecting to display for title (Sensex : 20850.74 * 451.32 (2.21 %)) ?

Kush
  • 909
  • 1
  • 8
  • 14
  • Suppose I need to show Data like 20850 Upsymbol 451.32 2.21%. You told to use regular expression how to do this please write something more – D S Nov 18 '13 at 11:56