From f8bc4cebbc4b6ce9133daadbbe53ed1d34058068 Mon Sep 17 00:00:00 2001 From: Peter Schaffluetzel Date: Sat, 26 Nov 2022 10:05:41 +0100 Subject: [PATCH] Update renderers.py The proposed changes allow to create child classes that include a namespace or other root attributes, e.g. class UrlXmlRenderer(XMLRenderer): root_tag_name = 'urlset' item_tag_name = 'url' root_attributes = {'xmlns': 'http://www.sitemaps.org/schemas/sitemap/0.9'} --- rest_framework_xml/renderers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework_xml/renderers.py b/rest_framework_xml/renderers.py index 81765e8..07a76b3 100644 --- a/rest_framework_xml/renderers.py +++ b/rest_framework_xml/renderers.py @@ -18,6 +18,7 @@ class XMLRenderer(BaseRenderer): charset = "utf-8" item_tag_name = "list-item" root_tag_name = "root" + root_attributes = {} def render(self, data, accepted_media_type=None, renderer_context=None): """ @@ -30,7 +31,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None): xml = SimplerXMLGenerator(stream, self.charset) xml.startDocument() - xml.startElement(self.root_tag_name, {}) + xml.startElement(self.root_tag_name, self.root_attributes) self._to_xml(xml, data)