0

Own XML

Hi all. How do I grab feeds from my own XML?

This are some parts of my code:

CODE
var MainView = new KONtx.Class({

ClassName: 'MainView',



Extends: KONtx.system.SidebarView,



config: {

RSSFeed: 'file:///devwidgets/siaokina.test.com.tv.widget/Contents/Javascript/views/Movies.xml',

RSSFeed_XML: false, //A simple holder for our XMl Feed that also acts a Network success indicator

RSSFeed_items: [] //Setup a Quick Array to hold our RSS Feed Items

},



createView: function() {



var self = this; //We need a variable to reference the main Class inside our button

//Create a button at the top of the so we can update the view by selecting the button

this.controls['button'] = new KONtx.control.TextButton({

label: 'Update RSS Feed',

styles: $content.styles.main.button,
events:{

//Setup a onSelect Event to handle the button action

onSelect:function(event){


self.grabRSS(self.config.RSSFeed);

}

}

}).appendTo(this);
grabRSS: function(url){

KONtx.utility.LoadingOverlay.on();

var self = this;
KONtx.utility.LoadingOverlay.off();
//I have no idea how to grab feeds from my own XML from here onwards
},

by
11 Replies
  • QUOTE (siaokina @ Mar 31 2011, 07:13 PM) <{POST_SNAPBACK}>
    Hi all. How do I grab feeds from my own XML?

    This are some parts of my code:

    CODE
    var MainView = new KONtx.Class({

    ClassName: 'MainView',



    Extends: KONtx.system.SidebarView,



    config: {

    RSSFeed: 'file:///devwidgets/siaokina.test.com.tv.widget/Contents/Javascript/views/Movies.xml',

    RSSFeed_XML: false, //A simple holder for our XMl Feed that also acts a Network success indicator

    RSSFeed_items: [] //Setup a Quick Array to hold our RSS Feed Items

    },



    createView: function() {



    var self = this; //We need a variable to reference the main Class inside our button

    //Create a button at the top of the so we can update the view by selecting the button

    this.controls['button'] = new KONtx.control.TextButton({

    label: 'Update RSS Feed',

    styles: $content.styles.main.button,
    events:{

    //Setup a onSelect Event to handle the button action

    onSelect:function(event){


    self.grabRSS(self.config.RSSFeed);

    }

    }

    }).appendTo(this);
    grabRSS: function(url){

    KONtx.utility.LoadingOverlay.on();

    var self = this;
    KONtx.utility.LoadingOverlay.off();
    //I have no idea how to grab feeds from my own XML from here onwards
    },


    This should get you started:

    CODE
    var MainView = new KONtx.Class({

    ClassName: 'MainView',



    Extends: KONtx.system.SidebarView,



    config: {

    RSSFeed: 'Javascript/views/Movies.xml',

    RSSFeed_XML: false, //A simple holder for our XMl Feed that also acts a Network success indicator

    RSSFeed_items: [] //Setup a Quick Array to hold our RSS Feed Items

    },



    createView: function() {



    ///var self = this; NOTE you don't need this, see below how you can reference the view from within a control's event listener;

    //Create a button at the top of the so we can update the view by selecting the button

    this.controls['button'] = new KONtx.control.TextButton({

    label: 'Update RSS Feed',

    styles: $content.styles.main.button,
    events:{

    //Setup a onSelect Event to handle the button action

    onSelect:function(event){


    this.getView().grabRSS(this.getView().config.RSSFeed);

    }

    }

    }).appendTo(this);
    },

    //NOTE grabRSS shouldn't be in createView so I moved it out;
    grabRSS: function(url){

    KONtx.utility.LoadingOverlay.on();

    var xml = XMLDOM.parse(filesystem.readFile(url); //NOTE this creates an XML DOM document;
    KONtx.utility.LoadingOverlay.off();
    //I have no idea how to grab feeds from my own XML from here onwards
    },


    Please refer to the online docs here.
    0
  • QUOTE (Benjamin Toll @ Mar 31 2011, 11:10 PM) <{POST_SNAPBACK}>
    This should get you started:

    CODE
    var MainView = new KONtx.Class({

    ClassName: 'MainView',



    Extends: KONtx.system.SidebarView,



    config: {

    RSSFeed: 'Javascript/views/Movies.xml',

    RSSFeed_XML: false, //A simple holder for our XMl Feed that also acts a Network success indicator

    RSSFeed_items: [] //Setup a Quick Array to hold our RSS Feed Items

    },



    createView: function() {



    ///var self = this; NOTE you don't need this, see below how you can reference the view from within a control's event listener;

    //Create a button at the top of the so we can update the view by selecting the button

    this.controls['button'] = new KONtx.control.TextButton({

    label: 'Update RSS Feed',

    styles: $content.styles.main.button,
    events:{

    //Setup a onSelect Event to handle the button action

    onSelect:function(event){


    this.getView().grabRSS(this.getView().config.RSSFeed);

    }

    }

    }).appendTo(this);
    },

    //NOTE grabRSS shouldn't be in createView so I moved it out;
    grabRSS: function(url){

    KONtx.utility.LoadingOverlay.on();

    var xml = XMLDOM.parse(filesystem.readFile(url); //NOTE this creates an XML DOM document;
    KONtx.utility.LoadingOverlay.off();
    //I have no idea how to grab feeds from my own XML from here onwards
    },


    Please refer to the online docs here.


    Why does the url change to 'Javascript/views/Movies.xml' instead of the url itself?
    0
  • QUOTE (siaokina @ Mar 31 2011, 11:39 PM) <{POST_SNAPBACK}>
    Why does the url change to 'Javascript/views/Movies.xml' instead of the url itself?

    Because that's how you reference a local file. Did you try it?
    0
  • QUOTE (Benjamin Toll @ Apr 1 2011, 12:01 AM) <{POST_SNAPBACK}>
    Because that's how you reference a local file. Did you try it?


    Yup. I have tried to work from your codes but it keep giving me this error.
    "Can't get a view which we don't have a valid config for"
    0
  • have you setup the view in the init.js file?
    0
  • QUOTE (WidgetRealm @ Apr 3 2011, 08:27 AM) <{POST_SNAPBACK}>
    have you setup the view in the init.js file?


    yup. i added include("Javascript/views/Movies.xml"); and still having the error.. i suspect the xml file location is not appropiate as it is an xml file but it is in views folder and if it should not be in the views folder, which folder should hold the xml file?
    0
  • We always pull our files from a server via a web service. I am not sure how you are going to change the movie list once the app is published.
    0
  • Technically, this line should throw an error when you are loading the application. You are missing a ")" in the line

    CODE
    var xml = XMLDOM.parse(filesystem.readFile(url);

    //Should be
    var xml = XMLDOM.parse(filesystem.readFile(url));
    0
  • The source you have provided is from our Developer Toolkit. I would take a look at the network.js file to see how we are calling a web service in the demo app.
    0
  • QUOTE (siaokina @ Apr 2 2011, 11:20 PM) <{POST_SNAPBACK}>
    Yup. I have tried to work from your codes but it keep giving me this error.
    "Can't get a view which we don't have a valid config for"

    This usually means that you have a typo somewhere in your init.js or where you're referencing a view.
    0
  • QUOTE (siaokina @ Apr 3 2011, 04:55 PM) <{POST_SNAPBACK}>
    yup. i added include("Javascript/views/Movies.xml"); and still having the error.. i suspect the xml file location is not appropiate as it is an xml file but it is in views folder and if it should not be in the views folder, which folder should hold the xml file?

    This is wrong. You shouldn't be including an xml file, you should be opening it and reading from it like how I did in my example code.

    Your initial question was how to read from an xml document on the local filesystem. I suspect that you didn't read the docs that I linked to. Please read them, it explains everything that you need to do.
    0

Recent Posts

in Getting Started / Beginners - Yahoo! TV Widgets