PDA

View Full Version : XML Reader trim (condense) white space?



harrypottar
12 Apr 2012, 9:07 AM
Still new to all this so learning as I go, moving from Flex to ExtJs

I have a model with some model associations loading from an XML file.

All working but I wondered what would be the best way to deal white space.

Some of the text nodes have nested data (loading into the associations)

for example:


<search >Search:
<search-options>
<online>OnLine</online>
<archives>Archives</archives>
<both>Online and Archives</both>
</search-options>
</search>



When I look at the model field for search, I get the text as expected but I get a bunch of white space and a new line.

I know I could create a new model field with a mapping function and use Ext.String.trim() which would trim the search field.

However is there a config to condense white space when reading xml or is there a more efficient way to trim the filed with out using a mapping function

harrypottar
12 Apr 2012, 9:38 AM
I tried both of these but neither work


{name: 'search', mapping: function(o) {
console.log(o['/search']);
return Ext.String.trim(o['/search']);
}, type: 'string'},



{name: 'search', mapping: function(o) {
console.log(o.search);
return Ext.String.trim(o.search);
}, type: 'string'},



This works but I get the newline and extra space


{name: 'search', mapping: '/',type: 'string'},


tia

Harry

harrypottar
13 Apr 2012, 3:26 PM
bump.

sorry for the bump, but struggling with this one, removing white space from text node

harrypottar
16 Apr 2012, 6:25 AM
In trying to solve another problem I stumbled on the answer and thought I would post in case anyone else was looking.

The answer was actually quite simple, I was trying to run a function on the mapping function when I should have been doing this on the covert function.


{name: 'filename', mapping: '/',type: 'string',convert: function(v){return Ext.String.trim(v);},defaultValue: 'Filename'},