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

XML data, one field has two possible xml constructs.

2 Answers 85 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 04 Jun 2012, 04:47 AM
I have some XML data that is constructed differently when the server detects a missing value
   <STORES>
...
      <CITY>Chattanooga</CITY>
...
   </STORES>
   <STORES>
...
      <CITY missing=" " />
...
   </STORES>

In the first and normal case my schema model defintion works fine
model: {
    fields: {
...
    ,   city:  "CITY/text()"
...
    }
}

In the second case when the server sends missing=" ", the grid shows [object Object]  instead of a null or blank value.

Is there a single specifier I can use for city: so that I get either #text or @missing ?

Thanks,
Richard

2 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 05 Jun 2012, 10:08 AM
Hello Richard,

Generally speaking, there is no such single specifier. As a possible workaround I would suggest to manually parse the data using the parse() method of the dataSource schema. For example:
schema: {
  parse: function(xml) {
    // parse the xml to a JavaScript object
    return result;
  }
}

I hope this helps.


Kind regards,
Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Richard
Top achievements
Rank 1
answered on 10 Jun 2012, 11:22 AM
Hi Iliana:

Instead of writing my own parser I slightly modified kendo.data.xml.js parseDOM:

Presume no children means a shorthand node <{some-name}/> and thus its #text is null or missing

Changed the loop over children from

for (node = element.firstChild; node; idx++,node = node.nextSibling) {


to

for (idx = 0,node = element.firstChild; node; idx++,node = node.nextSibling) {


so that idx tracks # of children.  After the loop idx is examined and empty text is assigned as needed:

    if (idx==0) {
        result[
'#text'] = '';
    }


The use of this code path could also be made conditional per a property of the DataSource schema: option,

schema: { type: 'xml', shorthandMissing: true, ... }
Tags
Data Source
Asked by
Richard
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Richard
Top achievements
Rank 1
Share this question
or