This is a migrated thread and some comments may be shown as answers.

Binding to remote XML Data

1 Answer 208 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Gabe Silvarajoo
Top achievements
Rank 2
Gabe Silvarajoo asked on 13 Apr 2012, 07:17 PM
Dear Kendo UI Team,

I have been studying the KendoUI Web examples and currently having problems getting data from a remote XML feed. Here's the example that I'm refering to Binding to XML Data and below is my code. I simply replace the source from local to Books.xml on the demo site.

Code:
<ul id="books"></ul>
 
            <script id="template" type="text/x-kendo-template">
                <li class="book">
                    <a href="#= url #">
                        <h3>#= title #</h3>
                    </a>
                    by #= author #
                </li>
            </script>
 
            <script>
                $(document).ready(function () {
                    function onChage() {
                        $("#books").html(kendo.render(template, this.view()));
                    }
 
                    // create a template using the above definition
                    var template = kendo.template($("#template").html());
 
                    var dataSource = new kendo.data.DataSource({
                        transport: {
                            // specify the XML file to read. The same as read: { url: "books.xml" }
                            read: "http://demos.kendoui.com/content/web/datasource/books.xml"
                        },
                        schema: {
                            // specify the the schema is XML
                            type: "xml",
                            // the XML element which represents a single data record
                            data: "/books/book",
                            // define the model - the object which will represent a single data record
                            model: {
                                // configure the fields of the object
                                fields: {
                                    // the "title" field is mapped to the text of the "title" XML element
                                    title: "title/text()",
                                    // the "author" field is mapped to the text of the "author" XML element
                                    author: "author/text()",
                                    // the "url" field is mapped to the text of the "url" XML element
                                    url: "url/text()",
                                    // the "cover" field is mapped to the "id" attribute of the "book" XML element
                                    cover: "@cover"
                                }
                            }
                        },
                        change: onChage
                    });
 
                    dataSource.read();
                });
            </script>

When I load the page, I don't get any data. Also, how can I see errors? Is there some code examples to display errors? Please advice. Thanks.

Gabe

1 Answer, 1 is accepted

Sort by
0
Hari
Top achievements
Rank 1
answered on 07 Dec 2012, 05:05 PM
Hi,
Were you able to resolve your issue? we are trying to set an XML Document as datasource for Kendo Tree view control and struck there. Can you help us?
Tags
Data Source
Asked by
Gabe Silvarajoo
Top achievements
Rank 2
Answers by
Hari
Top achievements
Rank 1
Share this question
or