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

Hyphens in Xml element names breaks DataSource

1 Answer 170 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 14 Feb 2012, 05:38 AM

Kendo DataSource does not appear to work with XML that has hyphenated (element) names.

For instance, try a working XML-bound demo and change the XML source element names and field references to include hyphen(s).

I'm not expecting to have to escape the '-' character in the field XPath expressions... am I overlooking something?

I don't have the luxury or modifying the web service that provides this data.

Would appreciate comments from anyone able to reproduce, work around, or otherwise enlighten me about this issue.

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 15 Feb 2012, 01:20 PM
Hi Andy,

I'm afraid that current hyphen within the XML node names is not supported. However, in order to workaround this limitation you should remove the hyphens before the data is processed. Similar to the following:

var dataSource = new kendo.data.DataSource({
       transport: {
           // specify the XML file to read. The same as read: { url: "books.xml" }
           read: {
               url: "books.xml",
               dataType: "text",
               dataFilter: function(data) {
                      return data.replace(/(<|<\/)([\w-]+)/g, function(match) { return match.replace(/\-/g, "") });
               }
         }
       },
       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
   });

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!
Tags
Data Source
Asked by
Andrew
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or