rbren / rss-parser

A lightweight RSS parser, for Node and the browser
MIT License
1.35k stars 209 forks source link

Unable to make use of processing attribute stripPrefix of node-xml2js library #99

Open theasteve opened 5 years ago

theasteve commented 5 years ago

I'm a bit confused by the documentation and am willing to create a PR to improve it once I have a better understanding of the following. In https://github.com/bobby-brennan/rss-parser#xml2js-passthrough states that you can pass options to xml2js parser. I have the following:

const parser = new Parser({
  xml2js: {
    stripPrefix: "xmlns:event"
  },
});

I would like to make use of stripPrefix of the xml2js library. It still a bit confusing to me how to use xml2js from the documentation. This new xml2js.Parser() as shown in the docs won't work. What I am tryin to accomplish is to get the namespace fields.

screen shot 2019-03-01 at 1 42 55 pm

from event a more descriptive image would be shown below:

screen shot 2019-02-27 at 11 31 18 am

However, when I try to console.log each item from the following function:

const convertRssIntoJson = rssFeed => {
   return new Promise((res, rej) => {
       parser.parseURL(rssFeed, (err, rss) => {
           if (err) {
               return rej(err);
           }
           // console.log(rss.stripPrefix()) is this how is use?
           rss.items.forEach(function(entry) {
             console.log(entry);
           });

           return res(rss);
       });
   });
};

I dont get the namespace fields from event. I would like to get those fields in the JSON without having to add customFields. How can I make use of stripPrefix option an use xml2js?

rbren commented 5 years ago

Currently the xml2js passthrough options are just passed to the xml2js constructor, not to parseString.

I'm happy to accept a PR that adds another option that can be passed to parseString to do things like stripPrefix.