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

XML Binding Confusion

4 Answers 315 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 07 Dec 2011, 08:13 AM

I am just getting started with Kendo and am very intrigued by what has been put together thus far.  

At the moment, I am trying to better understand the use of the Grid widget and binding to an external source, but I keep running into conflicting answers in this forum.

What I want to do is to bind to a standard web service (not JSON).   

Perhaps I am not understanding this completely, but it seems that in some discussions, people say this is not possible (http://www.kendoui.com/forums/framework/data-source/bind-to-remote-xml.aspx), but then I see other postings saying that it is (http://www.kendoui.com/forums/ui/grid/grid-data-binding-to-xml.aspx).

Either way, I cannot seem to get it to work, in fact, it doesn't even seem to hit my web service at all.   Can someone shed some light on this?

Here is my code:

<script>
    var dateRegExp = /^\/Date\((.*?)\)\/$/;
 
    function toDate(value) {
        var date = dateRegExp.exec(value);
        return new Date(parseInt(date[1]));
    }
 
    var esData = new kendo.data.DataSource({
        transport: {
            read: { url: "http://localhost/esplanning/esweb.asmx/EmployeeList", type: "xml" }
        }
    });
     
    $(document).ready(function() {
        $("#grid").kendoGrid({
            dataSource: esData,
            schema: {
                type: "xml",
                data: "/EmployeeListResponse/Results/RowSet/Rows"
            },
            height: 250,
            filterable: true,
            sortable: true,
            pageable: true });
    });
</script>


And my corresponding XML data:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Body>
        <EmployeeListResponse xmlns="http://tempuri.org/">
            <Results xmlns="" CubeName="Employee" ViewName="EmployeeList">
                <Scenario DimName="Scenario" ID="Working Budget" Name="Working Budget" />
                <EntityDept DimName="Entity-Dept" ID="1110-3030" Name="1110-3030" />
                <ProductLine_s DimName="Product Line_s" ID="1020" Name="Aviation Electronic Solutions" />
 
                <RowSet ColDims="Employee_m">
                    <Rows IsUpdated="false">
                        <Employee Name="All Employees - All Employees" DimName="Employee" ID="All Employees" IsUpdated="false" EmployeeName="All Employees">All Employees - All Employees</Employee>
                        <Position Name="Current" DimName="Position" ID="1" IsUpdated="false">Current</Position>
                    </Rows>
                    <Rows IsUpdated="false">
                        <Employee Name="Rai, Colleen - 0000000702" DimName="Employee" ID="0000000702" IsUpdated="false" EmployeeName="Rai, Colleen">Rai, Colleen - 0000000702</Employee>
                        <Position Name="Current" DimName="Position" ID="1" IsUpdated="false">Current</Position>
                    </Rows>
                    <Rows IsUpdated="false">
                        <Employee Name="Romero, Walter - 0000000806" DimName="Employee" ID="0000000806" IsUpdated="false" EmployeeName="Romero, Walter">Romero, Walter - 0000000806</Employee>
                        <Position Name="Current" DimName="Position" ID="1" IsUpdated="false">Current</Position>
                    </Rows>
                </RowSet>
            </Results>
        </EmployeeListResponse>
    </soap:Body>
</soap:Envelope>

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 09 Dec 2011, 10:21 AM
Hello Steven,

Looking at the code you have pasted it seems that  there are several issues:  

- schema should be declared inside dataSource definition
- data path is not correct
- model should be declare

$("#grid").kendoGrid({
    dataSource: {
        transport: {
            read: { url: "esweb.asmx/EmployeeList" }
        },
        schema: {
            type: "xml",
            data: "soap:Envelope/soap:Body/EmployeeListResponse/Results/RowSet/Rows",
            model: {
                fields: {
                    Employee: "Employee/text()"
                    //rest of field declaration...
                }
            }
        },
        pageSize: 10
    },
    filterable: true,
    sortable: true,
    pageable: true
});

Kind regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Steven
Top achievements
Rank 1
answered on 09 Dec 2011, 04:53 PM
Rosen,

Yeah, sorry about the bad code.  What I posted was after numerous attempts to try different things and it got a little messed up.  

However, I did get some more information that might help with this issue.

The following code does hit the web service (but of course nothing comes back in the table):

$("#grid").kendoGrid({
    dataSource: {
        type: "odata",
        transport: {
        },
        pageSize: 10,
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    }
});

However, as soon as I take away the type: "odata" or change it to "xml" it no longer hits the web service.

Also, when I try to incorporate the schema information, it also no longer hits the web service.    So something is going on, but I cannot see where, because no errors are being generated.   What is the best way to track this down?

    $("#grid").kendoGrid({
        dataSource: {
            type: "odata",
            transport: {
                read: "http://localhost/esplanning/esweb.asmx/EmployeeList"
            },
            schema: {
                type: "xml",
                data: "soap:Envelope/soap:Body/EmployeeListResponse/Results/RowSet/Rows",
                model: {
                    fields: {
                        Employee: "Employee/text()"
                        //rest of field declaration...
                    }
                }
            },
            pageSize: 10,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: true
        }
    });
 
});


0
Steven
Top achievements
Rank 1
answered on 09 Dec 2011, 05:17 PM
Ok, I started tracing the code in kendo.data.js and found that when "xml" is encountered as a type, the following line (1049) throws an error:  Object doesn't support this action.    Does this mean that only JSON is supported?  
that.reader = new kendo.data.readers[options.schema.type || "json" ](options.schema);
 
I am using the latest commercial KendoUI code (2011.3.1129).
Is there a difference between the commercial and the public version?
0
Rosen
Telerik team
answered on 12 Dec 2011, 10:41 AM
Hello Steven,

As you have noticed the odata type is not compatible with the xml returned from the server. Also as mentioned in one of the threads you have refer to in the initial message, the cross-domain xml requests are not supported. Therefore, you should make sure that the service, from which the data is coming from is in the same domain as the page on which dataSource is used. Thus you should be able to reference it for example as esweb.asmx/EmployeeList instead of http://localhost/esplanning/esweb.asmx/EmployeeList.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Steven
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Steven
Top achievements
Rank 1
Share this question
or