本文整理汇总了Python中django.utils.xmlutils.SimplerXMLGenerator方法的典型用法代码示例。如果您正苦于以下问题:Python xmlutils.SimplerXMLGenerator方法的具体用法?Python xmlutils.SimplerXMLGenerator怎么用?Python xmlutils.SimplerXMLGenerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.xmlutils
的用法示例。
在下文中一共展示了xmlutils.SimplerXMLGenerator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def render(self, data, accepted_media_type=None, renderer_context=None):
"""
Renders *obj* into serialized XML.
"""
if data is None:
return ''
elif isinstance(data, six.string_types):
return data
stream = StringIO()
xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
xml.startElement(self.root_node, {'xmlns': self.xmlns})
self._to_xml(xml, data)
xml.endElement(self.root_node)
xml.endDocument()
return stream.getvalue()
示例2: render
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def render(self, data, accepted_media_type=None, renderer_context=None):
"""
Renders `data` into serialized XML.
"""
if data is None:
return ""
stream = StringIO()
xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
xml.startElement(self.root_tag_name, {})
self._to_xml(xml, data)
xml.endElement(self.root_tag_name)
xml.endDocument()
return stream.getvalue()
示例3: render
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def render(self, data, accepted_media_type=None, renderer_context=None):
"""
Renders *obj* into serialized XML.
"""
# if data is None:
# return ''
# elif isinstance(data, six.string_types):
# return data
stream = StringIO()
xml = SimplerXMLGenerator(stream, self.charset)
xml.startDocument()
xml.startElement(self.root_node, {'xmlns': self.xmlns})
self._to_xml(xml, data)
xml.endElement(self.root_node)
xml.endDocument()
return stream.getvalue()
示例4: get_xml_export
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def get_xml_export(self, context):
results = self._get_objects(context)
stream = io.StringIO()
xml = SimplerXMLGenerator(stream, "utf-8")
xml.startDocument()
xml.startElement("objects", {})
self._to_xml(xml, results)
xml.endElement("objects")
xml.endDocument()
return stream.getvalue().split('\n')[1]
示例5: write
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding)
handler.startDocument()
handler.startElement("rss", self.rss_attributes())
handler.startElement("channel", self.root_attributes())
self.add_root_elements(handler)
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement("rss")
示例6: start_serialization
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def start_serialization(self):
"""
Start serialization -- open the XML document and the root element.
"""
self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
self.xml.startDocument()
self.xml.startElement("django-objects", {"version": "1.0"})
示例7: render
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def render(self, data):
if data is None:
return ''
stream = StringIO()
xml = SimplerXMLGenerator(stream, "utf-8")
xml.startDocument()
self.render_document(xml, data)
xml.endDocument()
return stream.getvalue()
示例8: start_serialization
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def start_serialization(self):
"""
Start serialization -- open the XML document and the root element.
"""
self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
self.xml.startDocument()
self.xml.startElement("django-objects", {"version" : "1.0"})
示例9: get_xml_export
# 需要导入模块: from django.utils import xmlutils [as 别名]
# 或者: from django.utils.xmlutils import SimplerXMLGenerator [as 别名]
def get_xml_export(self, context):
results = self._get_objects(context)
stream = StringIO.StringIO()
xml = SimplerXMLGenerator(stream, "utf-8")
xml.startDocument()
xml.startElement("objects", {})
self._to_xml(xml, results)
xml.endElement("objects")
xml.endDocument()
return stream.getvalue().split('\n')[1]