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
| Attribute | Type | Description |
|---|
| content_type | string = application/rss+xml; charset=utf-8 | The MIME type and character encoding used for the HTTP response header when serving the RSS feed. |
Constructor
Signature
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
| Name | Type | Description |
|---|
| outfile | file-like object | The destination stream where the generated RSS XML content will be written. |
| encoding | string | The character encoding to use for the XML document, such as 'utf-8'. |
Returns
| Type | Description |
|---|
null | Nothing is returned; the output is written directly to the outfile. |
@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
| Type | Description |
|---|
dict | A 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
| Name | Type | Description |
|---|
| handler | [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator) | The XML generator instance used to write the item tags and content. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| handler | [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator) | The XML generator instance used to write the processing instructions. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| handler | [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator) | The XML generator instance used to write the channel metadata elements. |
Returns
| Type | Description |
|---|
null | Nothing 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
| Name | Type | Description |
|---|
| handler | [SimplerXMLGenerator](../xmlutils/simplerxmlgenerator.md?sid=django_utils_xmlutils_simplerxmlgenerator) | The XML generator instance used to write the closing channel tag. |
Returns
| Type | Description |
|---|
null | Nothing is returned; the closing tag is written to the handler. |