Bind to remote xml

7 posts, 1 answers
  1. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Nov 2011 Link to this post

    How do I configure the widget to bind to this XML?

    http://www.google.com/ig/api?weather=hamilton,ON


    This is my definition so far...

    $(document).ready(function () {
        function onChange() {
            $("#weather-container").html(kendo.render(template, this.view()));
        }
     
        // create a template using the above definition
        var template = kendo.template($("#dashwidget-weather-template").html());
     
        var dataSource = new kendo.data.DataSource({
            transport: {
                // specify the XML file to read. The same as read: { url: "books.xml" }
                read: {
                    url: "http://www.google.com/ig/api?weather=hamilton",
                    dateType: "xml"
                }
            },
            schema: {
                // specify the the schema is XML
                type: "xml",
                // the XML element which represents a single data record
                data: "/weather/current_conditions",
                // define the model - the object which will represent a single data record
                model: {
                    fields: {
                        condition: "condition/text()",
                        temp: "temp_c/text()"
                    }
                }
            },
            change: onChange
        });
     
        dataSource.read();
    });
  2. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Nov 2011 Link to this post

    or:
    transport: {
                // specify the XML file to read. The same as read: { url: "books.xml" }
                read: {
                    url: "http://www.google.com/ig/api",
                    dateType: "xml",
                    data: {
                        weather: "Hamilton,ON"
                    }
     
                }
            },

    http://jsfiddle.net/fQJ2D/1/
  3. Kendo UI is VS 2017 Ready
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 Nov 2011 Link to this post

    Hi Steve,

     Binding to cross domain XML is not currently supported. You can download the XML only with an XMLHTTPRequest which supports cross origin resource sharing (CORS). There is of course JSONP which however will not work with XML for obvious reasons. You can check this blog post which explains this in more detail.

    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!
  5. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Nov 2011 Link to this post

    Aw darn, will it be supported for release?...or shortly after perhaps?

    Thanks,
    Steve
  6. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 18 Nov 2011 Link to this post

    Hello Steve,

    Does this web server have this http header enabled - Access-Control-Allow-Origin: * ? 

    If yes you can use it even now if you fix the typo - dateType should be dataType. You have also included mockjax which probably prevents all ajax requests from happening.

    If it doesn't support the required HTTP header we can't do anything. You would need to create a server side proxy.

    I ran a few tests and it seems it doesn't support access-control-allow-origin at the time being.

    All the best,

    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!
  7. Steve
    Steve avatar
    1851 posts
    Member since:
    Dec 2008

    Posted 18 Nov 2011 Link to this post

    Whoops dateType :)

    Thanks for trying, I'll consume it on my own service and feed it back as JSON instead then
  8. Tom
    Tom avatar
    2 posts
    Member since:
    Apr 2012

    Posted 28 Apr 2012 Link to this post

    Steve/Atanas, 

    I was wondering since this thread was created if KendoUI ever supported binding remote XML data?

    Thanks, 

    Tom
Back to Top
Kendo UI is VS 2017 Ready