This solution worked for me:
In case of generating Coupon code RSS Feed, magento generate wrong array so it didn't convert in xml that's why I was getting that error.
Solution:
app/code/Vendor/Namespace/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Framework\App\Feed" type="Vendor\Namespace\App\Feed" />
</config>
app/code/Vendor/Namespace/App/Feed.php
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Vendor\Namespace\App;
use Zend\Feed\Writer\FeedFactory;
use Magento\Framework\App\FeedFactoryInterface;
/**
* Default XML feed class
*/
class Feed extends \Magento\Framework\App\Feed
{
/**
* @var array
*/
private $feeds;
/**
* Feed constructor.
* @param array $data
*/
public function __construct(array $data)
{
$this->feeds = $data;
}
/**
* {@inheritdoc}
*/
public function getFormattedContent() : string
{
if(strpos($_SERVER['REQUEST_URI'], 'discounts') !== false){
$feedData = $this->feeds;
$feedData['title'] = 'My Title - Discounts and Coupons';
$feedData['description'] = 'My Title - Discounts and Coupons';
$this->feeds = $feedData;
}
return FeedFactory::factory($this->feeds)->export(FeedFactoryInterface::FORMAT_RSS);
}
}