Skip to main content

RssFeed

This class provides functionality to generate and write RSS syndication feeds in XML format. It handles the creation of the RSS channel, including metadata like titles, links, and descriptions, as well as the serialization of individual feed items. The class supports custom stylesheets and ensures compliance with RSS versioning and Atom namespace requirements.

Attributes

AttributeTypeDescription
content_typestring = application/rss+xml; charset=utf-8The MIME type and character encoding used for the HTTP response header when serving the RSS feed.

Constructor

Signature

def RssFeed() - > null

Methods


write()

@classmethod
def write(
outfile: file-like object,
encoding: string
) - > null

Generates the complete RSS XML document and writes it to the provided file-like object. This method orchestrates the creation of the XML declaration, stylesheets, root elements, and all feed items.

Parameters

NameTypeDescription
outfilefile-like objectThe destination stream where the generated RSS XML content will be written.
encodingstringThe character encoding to use for the XML document, such as 'utf-8'.

Returns

TypeDescription
nullNothing is returned; the output is written directly to the outfile.

rss_attributes()

@classmethod
def rss_attributes() - > dict

Builds a dictionary of attributes for the top-level < rss > element. This includes the RSS version and necessary XML namespace declarations.

Returns

TypeDescription
dictA dictionary containing the version string and Atom namespace URI.

write_items()

@classmethod
def write_items(
handler: [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)
) - > null

Iterates through all items in the feed and writes their corresponding < item > XML elements. Each item is populated with its specific attributes and child elements.

Parameters

NameTypeDescription
handler[SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)The XML generator instance used to write the item tags and content.

Returns

TypeDescription
nullNothing is returned; elements are written to the handler.

add_stylesheets()

@classmethod
def add_stylesheets(
handler: [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)
) - > null

Inserts XML processing instructions for stylesheets into the document. These must be added after the document start but before the root element to comply with W3C standards.

Parameters

NameTypeDescription
handler[SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)The XML generator instance used to write the processing instructions.

Returns

TypeDescription
nullNothing is returned; processing instructions are written to the handler.

add_root_elements()

@classmethod
def add_root_elements(
handler: [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)
) - > null

Adds the standard metadata elements to the < channel > section of the feed. This includes the title, link, description, language, and other feed-level properties.

Parameters

NameTypeDescription
handler[SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)The XML generator instance used to write the channel metadata elements.

Returns

TypeDescription
nullNothing is returned; elements are written to the handler.

endChannelElement()

@classmethod
def endChannelElement(
handler: [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)
) - > null

Closes the < channel > XML element. This is called after all root elements and items have been written to the feed.

Parameters

NameTypeDescription
handler[SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator)The XML generator instance used to write the closing channel tag.

Returns

TypeDescription
nullNothing is returned; the closing tag is written to the handler.