ExtJS 3.4 DomQuery Namespaces Hotfix

You may have noticed that in ExtJS 3.4 that you can’t use namespaces in your Ext.dataXmlReader.
So a xml reader defined like the example below does not work with the following xml:

1
2
3
4
5
6
7
var Employee = Ext.data.Record.create([
   {name: 'name', mapping: 'gml:name'},    
   {name: 'gml:occupation'}                
]);
var myReader = new Ext.data.XmlReader({
   record: "gml|row" // The repeated element with gml namespace (gml:row)
}, Employee);

The above should consume an xml file defined like so:

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
 <gml:row>
   <gml:name>Bill</gml:name>
   <gml:occupation>Gardener</gml:occupation>
 </gml:row>
 <gml:row>
   <gml:name>Ben</gml:name>
   <gml:occupation>Horticulturalist</gml:occupation>
 </gml:row>
</dataset>

But it doesn’t…
That is because ExtJS 3.4 DomQuery does not support namespaces. They fixed this problem in 4 but those of you still using the 3.4 framework might find my hotfix useful. If just interested in using the files themselves I have attached them at the bottom of this post. Here are the changes I made:

Changed:

1
2
3
// tagTokenRe = /^(#)?([\w\-\*]+)/,  // Removed
tagTokenRe = /^(#)?([\w\-\*\|\\]+)/, // Added: allows vertical bars to be included
supportsColonNsSeparator,            // Added

Then Changed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//while(!(modeMatch = path.match(modeRe))){
// var matched = false;
// for(var j = 0; j < matchersLn; j++){
//    var t = matchers[j];
//    var m = path.match(t.re);
//    if(m){
//       fn[fn.length] = t.select.replace(tplRe, function(x, i){
//return m[i];
//});
//       path = path.replace(m[0], "");
//       matched = true;
//       break;
//    }
// } 
// if(!matched){
//    throw 'Error parsing selector, parsing failed at "' + path + '"';
// }
//}
//if(modeMatch[1]){
// fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
// path = path.replace(modeMatch[1], "");
//}
while (!(modeMatch = path.match(modeRe))) {
   var matched = false;
   for (var j = 0; j < matchersLn; j++) {
      var t = matchers[j];
      var m = path.match(t.re);
      if (m) {
         fn[fn.length] = t.select.replace(tplRe, function (x, i) {
            return m[i];
         });
         path = path.replace(m[0], "");
         matched = true;
         break;
      }
   }

   if (!matched) {
      throw 'Error parsing selector, parsing failed at "' + path + '"';
   }
}
if (modeMatch[1]) {
   fn[fn.length] = 'mode="' + modeMatch[1].replace(trimRe, "") + '";';
   path = path.replace(modeMatch[1], "");
}

Hotfix:
ext-all-debug-namespaces.js
ext-all-namespaces.js

Leave a Reply

Your email address will not be published. Required fields are marked *