DataReelDataReelC++ Toolkit Documentation

RSS Feed Classes

Contents

Overview
Data Structures
Public Data Members
Functions
Example

Overview

The gxRSSfeed class and its data structures are declared in gxsrss.h and implemented in gxsrss.cpp. They are used to write an RSS news feed as XML text. The caller fills in the channel data, including a list of items, and calls WriteFeed() to get the feed in a gxString object.

NOTE: Despite the RSS parser name given to this module in some places, the code only writes feeds. There is no function to read or parse an existing RSS feed. To read a feed file, use the gxsXML parser.

The rss_version member selects the output format. A version of 1.x writes an RSS 1.0 (RDF) document with an <rdf:RDF> root. Any other version (the default is "2.0") writes a document with an <rss> root in the RSS 2.0 format. This includes versions 0.91 and 0.92, which use the same format.

All text fields are encoded. The characters &, <, >, ' and " are replaced with XML entity references, so store plain text in the fields. The only exceptions are channel.skiphours and channel.skipdays, which hold <hour> and <day> elements and are written as given. NOTE: 10/14/2026: Fixed: only the description fields were encoded, so a title, link or other field with a & or < character made the feed invalid XML. Code that already stored encoded text in these fields must now store plain text instead.

Data Structures

Channel image. The <image> element is written when url, link and title are set. In RSS 2.0 output the description, width and height are written when they are not empty. In RSS 1.0 output they are not used. NOTE: 10/14/2026: Fixed: RSS 2.0 output left out the image unless the optional description was set.

struct gxRSSimage
{
  // Required elements
  gxString url;   // URL of a GIF, JPEG or PNG image that represents the channel.
  gxString link;  // URL of the site, when the channel is rendered, the image is a link to the site.
  gxString title; // Describes the image, it's used in the ALT attribute of the HTML <img> tag when
                  // the channel is rendered in HTML.

  // Optional elements
  gxString description; // Contains text that is included in the TITLE attribute
                        // of the link formed around the image in the HTML rendering.
  gxString width;       // Maximum value for width is 144, default value is 88.
  gxString height;      // Maximum value for height is 400, default value is 31.
};

Channel text input box. The text input element is written only when all four members are set. It is named <textInput> in RSS 2.0 output and <textinput> in RSS 1.0 output, as the two specifications require.

struct gxRSStextinput
{
  gxString title;       // The label of the Submit button in the text input area.
  gxString description; // Explains the text input area.
  gxString name;        // The name of the text object in the text input area.
  gxString link;        // The URL of the CGI script that processes text input requests.
};

Channel cloud. The RSS 2.0 <cloud> element is written as an empty element with its settings as attributes when the domain member is set, for example: <cloud domain="rpc.example.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap" />. All five attributes are always written, because the RSS 2.0 specification requires them. The values are XML encoded. It is not used in RSS 1.0 output. Clear() empties all members and is_null() returns true when the domain is empty. NOTE: 10/24/2026: Added in version 6.0. The channel cloud member used to be a gxString written as element text, which is not valid RSS.

struct gxRSScloud
{
  void Clear();
  int is_null() const;

  gxString domain;            // Domain name or IP address of the cloud
  gxString port;              // TCP port the cloud runs on
  gxString path;              // Location of the cloud's responder
  gxString registerprocedure; // Name of the procedure to call to register
  gxString protocol;          // xml-rpc, soap or http-post
};

Feed item. The title, link and description are always written. In RSS 2.0 output the other members are written only when they are not empty. In RSS 1.0 output only title, link and description are used.

struct gxRSSitem
{
  // Required
  gxString title;       // The title of the item
  gxString link;        // The URL of the item.
  gxString description; // The item synopsis.

  // Required in RSS version 2.0
  gxString pubdate; // Indicates when the item was published: Sun, 19 May 2002 15:21:36 GMT
  gxString guid;    // A string that uniquely identifies the item.

  // Optional
  gxString author;    // Address of the author of the item.
  gxString category;  // Includes the item in one or more categories.
  gxString comments;  // URL of a page for comments relating to the item.
  gxString enclosure; // Describes a media object that is attached to the item. More.
  gxString source;    // The RSS channel that the item came from. More.
};

Feed channel. The title, link and description are always written. In RSS 2.0 output the optional members language, copyright, managingeditor, webmaster, pubdate, lastbuilddate, category, generator, docs, cloud and ttl are written only when they are not empty. The rating member is written as <rating>. The skiphours and skipdays members are written as <skipHours> and <skipDays>. Their text is written as given, so store the <hour> or <day> elements in them, for example "<hour>1</hour><hour>2</hour>". NOTE: 10/14/2026: Fixed: rating, skiphours and skipdays were never written. In RSS 1.0 output only title, link, description, image, items and textinput are used.

struct gxRSSchannel
{
  // Required channel elements
  gxString title;       // The name of the channel.
  gxString link;        // The URL to the HTML website corresponding to the channel
  gxString description; // Phrase or sentence describing the channel.

  // Optional channel elements
  gxString language;       // The language the channel is written in.
  gxString copyright;      // Copyright notice for content in the channel.
  gxString managingeditor; // Email address for person responsible for editorial content.
  gxString webmaster;      // Email address for person responsible for technical issues.
  gxString pubdate;        // The publication date for the content in the channel:
                           // Date and Time Specification of RFC 822
                           // Sat, 07 Sep 2002 00:00:01 GMT
  gxString lastbuilddate;  // The last time the content of the channel changed:
                           // Sat, 07 Sep 2002 09:42:31 GMT
  gxString category;  // Specify one or more categories that the channel belongs to.
  gxString generator; // A string indicating the program used to generate the channel.
  gxString docs;      // A URL that points to the documentation for the format used in the RSS file.
  gxRSScloud cloud; // 10/24/2026: Was a gxString. Allows processes to register with a cloud to be notified of updates to the channel,
                      // implementing a lightweight publish-subscribe protocol for RSS feeds.
  gxString ttl;       // Time to live is a number of minutes that indicates how long a channel can be
                      // cached before refreshing from the source.
  gxString rating;    // The PICS rating for the channel.
  gxString skiphours; // A hint for aggregators telling them which hours they can skip.
  gxString skipdays;  // A hint for aggregators telling them which days they can skip

  // Optional channel sub-elements
  gxList<gxRSSitem> items;  // List of channel items
  gxRSSimage image;         // Specifies a GIF, JPEG or PNG image that can be displayed with the channel.
  gxRSStextinput textinput; // Specifies a text input box that can be displayed with the channel.
};

Items are written in list order. Add them with the gxList Add() function, which stores a copy of each item.

Public Data Members

class gxRSSfeed
{
  ...
public:
  // RSS required feed elements
  gxRSSchannel channel;

  // Document formatting members
  gxString xml_version;
  gxString rss_version;
  gxString encoding;
};

channel - The channel data written to the feed. See gxRSSchannel.

xml_version - Version written in the "<?xml version=... ?>" header. Set to "1.0" by Clear().

rss_version - RSS version. Set to "2.0" by Clear(). The value is converted to an integer with Atoi() to choose the output format, so "1.0" selects RSS 1.0 output and any other value, including "0.91", selects the <rss> format. NOTE: 10/14/2026: Fixed: "0.91" and "0.92" selected RSS 1.0 (RDF) output. In RSS 2.0 output the string is written as given in <rss version="...">.

encoding - Optional encoding written in the XML header, for example "UTF-8". If empty, no encoding attribute is written. Cleared by Clear().

Functions

gxRSSfeed::gxRSSfeed()
gxRSSfeed::~gxRSSfeed()
gxRSSfeed::Clear()
gxRSSfeed::encode_xhtml()
gxRSSfeed::WriteFeed()
gxRSSfeed::write_rss1_feed()
gxRSSfeed::write_rss2_feed()

gxRSSfeed::gxRSSfeed()

Default class constructor. Calls Clear() to set the document formatting members and empty the channel. Objects cannot be copied or assigned, because the gxList item list does not allow copying.

gxRSSfeed::~gxRSSfeed()

Class destructor. It does no work of its own.

void gxRSSfeed::Clear()

Public member function used to reset the feed. Sets xml_version to "1.0" and rss_version to "2.0", clears encoding, and clears every channel field, the image, the text input and the item list. NOTE: 10/14/2026: Fixed: the channel data, including the item list, was not cleared.

int gxRSSfeed::encode_xhtml(const gxString &unencoded_str, gxString &encoded_str)

Internal processing function (declared public) used to copy "unencoded_str" to "encoded_str" and replace the characters &, <, >, ' and " with &amp;amp;, &amp;lt;, &amp;gt;, &amp;apos; and &amp;quot;. Always returns 1.

int gxRSSfeed::WriteFeed(gxString &feed)

Public member function used to write the complete feed into the "feed" string. Any previous contents of "feed" are replaced. Calls write_rss1_feed() if the integer value of rss_version is 1, otherwise calls write_rss2_feed(). Always returns 1. The function does not check that the required channel or item fields are set. NOTE: 10/14/2026: Fixed: any version below 2, including 0.91 and 0.92, was written as RSS 1.0.

int gxRSSfeed::write_rss1_feed(gxString &feed)

Internal processing function (declared public) used to write an RSS 1.0 (RDF) document into "feed". The channel's rdf:about value is the channel link. The <items> sequence lists the link of each item, and each <item> uses its link as its rdf:about value. The image and text input references use the image URL and the text input link, and are written only when the image or text input is written. Always returns 1. NOTE: 10/14/2026: Fixed: these values were fixed sample addresses from xml.com, and the <items> sequence always listed the same two sample addresses.

int gxRSSfeed::write_rss2_feed(gxString &feed)

Internal processing function (declared public) used to write an RSS 2.0 document into "feed". The XML header and <rss> root are followed by a <channel> element with the channel fields, the optional <image> and <textInput> elements and one <item> element per item. Always returns 1. NOTE: 10/14/2026: Fixed: channel.cloud was written as "<cloud>...<channel>", which made the feed invalid XML. It is now closed with </cloud>. The text input element was named <textinput>; it is now <textInput> as the RSS 2.0 specification requires. NOTE: 10/24/2026: The cloud element is now written with the domain, port, path, registerProcedure and protocol attributes from the gxRSScloud member, the form the specification gives. It used to be written as element text.

Example

No example program in the distribution uses these classes (examples_general/xml_parser/testprog.cpp only includes gxsrss.h). The following minimal example builds a feed with one item and prints it.

#include <iostream>
using namespace std;

#include "gxsrss.h"

int main()
{
  gxRSSfeed rss; // Defaults: XML version 1.0, RSS version 2.0
  rss.encoding = "UTF-8";

  rss.channel.title = "Example News";
  rss.channel.link = "http://www.example.com/";
  rss.channel.description = "News & updates"; // Descriptions are encoded
  rss.channel.language = "en-us";

  gxRSSitem item;
  item.title = "First headline";
  item.link = "http://www.example.com/news/1.html";
  item.description = "Text of the first story.";
  item.pubdate = "Sun, 19 May 2002 15:21:36 GMT";
  item.guid = "http://www.example.com/news/1.html";
  rss.channel.items.Add(item);

  gxString feed;
  rss.WriteFeed(feed);
  cout << feed.c_str();
  return 0;
}

The program prints the following feed:

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0">
  <channel>
    <title>Example News</title>
    <link>http://www.example.com/</link>
    <description>
      News &amp; updates
    </description>
    <language>en-us</language>

    <item>
      <title>First headline</title>
      <link>http://www.example.com/news/1.html</link>
      <description>
        Text of the first story.
      </description>
      <pubDate>Sun, 19 May 2002 15:21:36 GMT</pubDate>
      <guid>http://www.example.com/news/1.html</guid>
    </item>

  </channel>
</rss>