0

Getting Data From Database

Hi,

My requirement is to get the playlist from the DB and need to play on TV, which could be the better way to do this. Can I connect to DB and get the data or can I get from xml ( CAN I ACCESS XML FROM WEB).


Thanks
Swarupa

by
9 Replies
  • QUOTE (swarupa @ Oct 8 2010, 02:22 AM) <{POST_SNAPBACK}>
    Hi,

    My requirement is to get the playlist from the DB and need to play on TV, which could be the better way to do this. Can I connect to DB and get the data or can I get from xml ( CAN I ACCESS XML FROM WEB).


    Thanks
    Swarupa

    You can make request to Web service(i.e PHP script) which can connect to DB and return XML or anything else to your TV.

    Simplify example:
    CODE
    var request = new URL();
    request.location = url;
    request.postData = params;

    request.fetchAsync(function(u){
    if (u.responce == 200){
    log(u.result) // <= Your XML should be here
    }
    });


    p.s. Yahoo! documentation about URL class is lost in new pfd :r
    0
  • This is exactly, including using URL class, how I do it in an YCTV widget that has made it most of the way through the Yahoo! QA process. However, if you are creating new server side code it is much better to return JSON than XML. The TV's parse JSON much more quickly than XML and I've seen hints of bugs in the XML parsing.
    0
  • To chime in on the XMl parsing - it is fine for loading smaller amounts of data and parsing is a bit slower.

    The real issues appear when loading XML files over 40Kb. We have seen the XML parser freeze, return partial data sets, and crash the platform - on certain devices, never in the simulator.

    You will also may see issues with using the Pager functionality and handling growing datasets while loading chunked data.
    0
  • QUOTE (WidgetRealm @ Oct 10 2010, 06:37 PM) <{POST_SNAPBACK}>
    To chime in on the XMl parsing - it is fine for loading smaller amounts of data and parsing is a bit slower.

    The real issues appear when loading XML files over 40Kb. We have seen the XML parser freeze, return partial data sets, and crash the platform - on certain devices, never in the simulator.

    You will also may see issues with using the Pager functionality and handling growing datasets while loading chunked data.


    I will be retrieving XML pages that probably average 70Kb in size (I browsed to the XML then saved as file to get the 70Kb size).

    What you are saying concerns me. As far as I know, the site that I will be accessing does not use JSON.

    What would you suggest?

    Thanks,

    Ray
    0
  • You can write a simple PHP to JSON converter like this to be in the middle.

    CODE
    <?PHP
    $xml = simplexml_load_file(urldecode($_GET['url']));
    echo json_encode($xml);
    ?>
    0
  • QUOTE (WidgetRealm @ Jan 9 2011, 04:33 PM) <{POST_SNAPBACK}>
    You can write a simple PHP to JSON converter like this to be in the middle.

    CODE
    <?PHP
    $xml = simplexml_load_file(urldecode($_GET['url']));
    echo json_encode($xml);
    ?>


    Bear with me as I am not up to snuff with programming this stuff.

    The XML I will be getting is on a server out on the web. Does the YCT development
    understand PHP? I'm confused.......
    0
  • No. You would need a webserver (PHP, Apache) as a middleman. It can be really light weight. Try using a GoDaddy server with their free domain hosting.

    The service flow might look like this:
    Application -> PHP server -> XML Content Feed -> PHP Server -> Application

    1) Application sends out the request to PHP server with the URL for the XML Content
    2) The PHP server then calls the URL passed in and loads the XML Content Feed via the simplexml_load_file() function
    3) The PHP server then coverts the XML->JSON and returns the JSON to the application by echoing the XML through json_encode() function
    4) The application does something with the returned JSON
    0
  • QUOTE (WidgetRealm @ Jan 9 2011, 08:20 PM) <{POST_SNAPBACK}>
    No. You would need a webserver (PHP, Apache) as a middleman. It can be really light weight. Try using a GoDaddy server with their free domain hosting.

    The service flow might look like this:
    Application -> PHP server -> XML Content Feed -> PHP Server -> Application

    1) Application sends out the request to PHP server with the URL for the XML Content
    2) The PHP server then calls the URL passed in and loads the XML Content Feed via the simplexml_load_file() function
    3) The PHP server then coverts the XML->JSON and returns the JSON to the application by echoing the XML through json_encode() function
    4) The application does something with the returned JSON


    Thanks for the reply. I've successfully gotten through steps 1-3.
    Actually, steps 2-3. Steps 1 and 4 are obviously the hardest.....for me anyway...
    Now the hard part....
    0
  • P.S. this is the doc for the URL class that I use
    http://manual.widgets.yahoo.com/wwhelp/wwh...nc.html#1171423
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets