How do I combine RSS feeds and then maintain XML feed structure?

I’ve used the RSS merger to combine feeds just fine, but when I go to return a custom http response that includes the merged feed, it loses the original RSS XML structure. Is there a simple way to get this working?

Hi @whoof , I had a few questions:

  • Could you share the code or action configuration you’re using to issue the HTTP response so we can see exactly how it’s configured?
  • Are you returning a Content-Type header of application/xml with the HTTP response to signal to the client that this is XML?
  • If you return the XML from the step as a step export (using return), copy the XML, and paste it into an XML validator, is the XML valid? If it fails to parse as XML, the HTTP client may not be able to handle it.

Thanks,
Dylan

Hi @dylburger, thanks for the help.
I’m using the following overarching config:
screenshot of apps

The rss_merge_rss_feed seems to get the xml just fine and then returns it as js object to the code section.

The code then looks like this:


export default defineComponent({
  async run({ steps, $ }) {
    await $.respond({
      status: 200,
      headers: { "Content-Type": "application/xml" },
      body: steps.rss_merge_rss_feeds.$return_value,
    })
  },
})

I get this failure when using the Content-Type application/xml. I suppose because in the prior step, the xml is manipulated on merge. I’ve tried to manually restitch xml in code but it’s not pretty or working out.

Hi @whoof,

I believe the issue is that the Merge RSS Feeds action is converting the XML to a Javascript Object, which is great for use in a Node.js code step and using that data downstream with other actions.

However, to return XML from your workflow, you’ll need to also convert this Javascript Object back into an XML string. Much like using JSON.stringify(object) to convert an object into JSON.

Here’s a quick proof of concept using xml-js:

import convert from 'xml-js'

// To use previous step data, pass the `steps` object to the run() function
export default defineComponent({
  async run({ steps, $ }) {
    const data = {
      "_declaration": {
        "_attributes": {
        "version": "1.0",
        "encoding": "utf-8"
        }
      },
      items: steps.merge_rss_feeds.$return_value
    }

    var options = {compact: true, ignoreComment: true, spaces: 4};
    var result = convert.js2xml(data, options);

    return result
  },
})

You’ll need to modify this code to meet your needs but this conversion step should happen between the merging of the feeds and the final HTTP response.

Hope this helps!

Thanks, this is a step in the right direction. How do you know which modules are available, and I’m surprised by the api for convert taking in these underscored field names.

Is there a simple way to make this RSS compatible like the inputs were? I’m getting this error in readers and on render.

Any NPM package is available for use in a Node.js code step. I just selected one that I’m familiar with. But you’re free to use any NPM packaged you’d like in a Node.js code step.

Sorry, XML conversion isn’t as implicit, you’ll need to read the documentation for the JS to XML module you’d prefer and make it match against the XML feeds you’re consuming.