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

Bug, data source fails when there's only one element in an XML file

6 Answers 107 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Benjamin
Top achievements
Rank 1
Benjamin asked on 22 Oct 2011, 09:16 PM
It seems that when there's only one XML element, the DropDownList fails to show it, and instead shows 'undefined' five times. Very odd. No errors in the console.

UPDATE: It seems each of the five "undefined" entries in the drop down correspond to the 5 xml elements nested within the doc. So its parsing the doc but failing to map to the schema. If I add the 2nd item (a duplicate), it loads them both fine.

6 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 24 Oct 2011, 07:35 AM
Hi Benjamin,

Could you please provide a bit more information about the XML's structure and declaration of the DataSource and DropDownList.

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!
0
Frantisek
Top achievements
Rank 1
answered on 04 Nov 2011, 01:58 PM
Hi,

I have similar problem as Benjamin. When I have one item in xml data source, loading into grid fails, but when I get two or more items, grid works fine. I attached 2 printscreens of what I get. There are no errors in console.

Definition of data source and grid

var dataSource = new kendo.data.DataSource({
        transport: {
            dataType: "xml",
            read: "xmlDataSource.php"
        },
        schema: {
            type: "xml",
            data: "/items/item",
            model: {
                fields: {
                    name: "name/text()",
                    code: "code/text()",
                    desc: "desc/text()",
                    price_tax: "price_tax/text()",
                    id_item: "id_item/text()",
                    currency: "currency/text()"
                }
            }
        },
        pageSize: 100,
        serverPaging: true,
        serverSorting: true
    });
 
    $("#grid").kendoGrid({
        dataSource: dataSource,
        scrollable: true,
        sortable: true,
        pageable: true,
        groupable: true,
        columns: [
        {field: "code", title: "Kód", width: "10px"},
        {field: "name", title: "Název produktu", width: "50px"},
        {field: "desc", title: "Popis", width: "80px"},
        {field: "price_tax", title: "Cena", width: "20px"},
        {field: "amount", title: " ", width: "50px",template: GRID_AMOUNT_INPUT},
        {field: "buy", title: " ", width: "50px",template: GRID_ADDTOCART_BUTTON},
        ]
    });

When I use dataSource.options.schema.data = "/items" instead of "/items/item", it works with one item in xml file, but not for more. Its weird ...

Then definition looks like this:

var dataSource = new kendo.data.DataSource({
        transport: {
            dataType: "xml",
            read: "xmlDataSource.php"
        },
        schema: {
            type: "xml",
            data: "/items",
            model: {
                fields: {
                    name: "name/text()",
                    code: "code/text()",
                    desc: "desc/text()",
                    price_tax: "price_tax/text()",
                    id_item: "id_item/text()",
                    currency: "currency/text()"
                }
            }
        },
        pageSize: 100,
        serverPaging: true,
        serverSorting: true
    });
 
    $("#grid").kendoGrid({
        dataSource: dataSource,
        scrollable: true,
        sortable: true,
        pageable: true,
        groupable: true,
        columns: [
        {field: "code", title: "Kód", width: "10px"},
        {field: "name", title: "Název produktu", width: "50px"},
        {field: "desc", title: "Popis", width: "80px"},
        {field: "price_tax", title: "Cena", width: "20px"},
        {field: "amount", title: " ", width: "50px",template: GRID_AMOUNT_INPUT},
        {field: "buy", title: " ", width: "50px",template: GRID_ADDTOCART_BUTTON},
        ]
    });

Is it a bug or am I doing anything wrong?

Thanks for help,
Frantisek.
0
Rosen
Telerik team
answered on 04 Nov 2011, 03:41 PM
Hi Frantisek,

In both cases you should use  data: "/items/item" as this is the "path selector" for the item from the root.

All the best,
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
Frantisek
Top achievements
Rank 1
answered on 04 Nov 2011, 03:57 PM
Thanks for the answer.

I understand what you mean. But when I've one <item> tag in XML file and using data: "/items/item", I'm  getting results as you can see in grid-xmldatasource-with-1-item.jpg. Definition data: "/items/item" works only if I have 2 or more <item> tags in XML file.
0
Rosen
Telerik team
answered on 07 Nov 2011, 12:40 PM
Hello Frantisek,

Indeed, you are correct, I was able to observed the described behavior. We managed to address it and the fix will be included in the next version of the library.

Thank you for reporting this.

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
Selvamani
Top achievements
Rank 1
answered on 07 Feb 2013, 01:54 PM
Hi Rosen

Hi have an issue with binding an xml to grid 
my sample xml is 

<id> 
 <r rn="1" sel="0">
  <vw n="address" v="Mycomp" />
  <vw n="description" v="AdminOU" />
  <vw n="identifier" v="1" />
  <vw n="mlouname" v="" />
     <vw n="remarks" v="Administration Unit" />
</r>
<r rn="2" sel="0">
    <vw n="address" v="Mycomp" />
  <vw n="description" v="SASDesignOU" />
  <vw n="identifier" v="2" />
  <vw n="mlouname" v="" />
  <vw n="remarks" v="SAS Design  Unit" />
</r>
 </id>

each value in the <vw> element in the <r> should be mapped to the column of the grid,  but kendo is not accepting the duplication of <vw> tag inside the <r> element .. can u help me...
Tags
Data Source
Asked by
Benjamin
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Frantisek
Top achievements
Rank 1
Selvamani
Top achievements
Rank 1
Share this question
or