Skip to content

Commit

Permalink
fix(rss): Fix parsing RDF feeds
Browse files Browse the repository at this point in the history
closes #22
  • Loading branch information
fent committed Feb 22, 2018
1 parent 15d56a2 commit 66da5eb
Show file tree
Hide file tree
Showing 3 changed files with 1,098 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/xmlfeedparser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

const sax = require('sax');


Expand Down Expand Up @@ -85,10 +87,9 @@ module.exports = (buffer) => {

// First start listening for the root tag.
var openf1 = function(node) {
var type;
if (node.name === 'channel' || node.name === 'feed') {
if (node.name === 'feed') {
type = 'atom';
let type = 'atom';
obj.type = type;
this.emit('type', type);
}
Expand All @@ -98,8 +99,8 @@ module.exports = (buffer) => {
parser.on('opentag', onopentag);
parser.on('closetag', onclosetag);

} else if (node.name === 'rss') {
type = 'rss ' + node.attributes.version;
} else if (node.name === 'rss' || node.name === 'rdf:rdf') {
let type = 'rss ' + (node.attributes.version || '1.0');
obj.type = type;
this.emit('type', type);
} else {
Expand Down Expand Up @@ -150,9 +151,13 @@ module.exports = (buffer) => {
obj[key] = cleanObj(obj[key]);

if (!stack.length) {
key = key === 'entry' || key === 'items' ? 'item' : key;
parser.emit(key, data);
if (!buffer) { delete obj[key]; }
var skey = key === 'entry' || key === 'items' ? 'item' : key;
// Some feeds will contain a summary of items at the top.
// Ignore this.
if (key !== 'items' || Array.isArray(data)) {
parser.emit(skey, data);
if (!buffer) { delete obj[key]; }
}
}
}

Expand Down
Loading

0 comments on commit 66da5eb

Please sign in to comment.