Permalink
Browse files

Handle namespaced elements that use nondefault namespace prefixes

  • Loading branch information...
1 parent e02b5c6 commit c6e4b465382eeabcc55e95242a4f644d31bc8be7 @danmactough committed Aug 31, 2012
Showing with 1,139 additions and 5 deletions.
  1. +14 −5 main.js
  2. +1,097 −0 test/feeds/wapowellness-altns.xml
  3. +28 −0 test/namespacedElements-02.js
View
19 main.js
@@ -861,6 +861,7 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
, node = { '#name' : el
, '#prefix' : ''
, '#local' : '' }
+ , stdEl
, item
, baseurl
;
@@ -876,6 +877,9 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
node['#prefix'] = el[0];
node['#local'] = el.slice(1).join(':');
node['#type'] = 'rdf';
+ } else {
+ node['#prefix'] = utils.nsprefix(n['#uri']) || n['#prefix'];
+ node['#local'] = el.slice(1).join(':');
}
} else {
node['#local'] = node['#name'];
@@ -960,12 +964,17 @@ FeedParser.prototype.handleCloseTag = function (el, scope){
}
if (parser.stack.length > 0) {
- if (!parser.stack[0].hasOwnProperty(node['#local'] || node['#name'])) {
- parser.stack[0][node['#local'] || node['#name']] = n;
- } else if (parser.stack[0][node['#local'] || node['#name']] instanceof Array) {
- parser.stack[0][node['#local'] || node['#name']].push(n);
+ if (node['#prefix'] && node['#local'] && !node['#type']) {
+ stdEl = node['#prefix'] + ':' + node['#local'];
+ } else {
+ stdEl = node['#local'] || node['#name'];
+ }
+ if (!parser.stack[0].hasOwnProperty(stdEl)) {
+ parser.stack[0][stdEl] = n;
+ } else if (parser.stack[0][stdEl] instanceof Array) {
+ parser.stack[0][stdEl].push(n);
} else {
- parser.stack[0][node['#local'] || node['#name']] = [parser.stack[0][node['#local'] || node['#name']], n];
+ parser.stack[0][stdEl] = [parser.stack[0][stdEl], n];
}
} else {
parser.nodes = n;
Oops, something went wrong.

0 comments on commit c6e4b46

Please sign in to comment.