Format data into XML.

def _format_data(self, data, charset):
        """ Format data into XML. """

        if data is None or data == '':
            return u''

        stream = StringIO.StringIO()
        xml = SimplerXMLGenerator(stream, charset)
        xml.startDocument()
        xml.startElement(self._root_element_name(), {})
        self._to_xml(xml, data)
        xml.endElement(self._root_element_name())
        xml.endDocument()
        return stream.getvalue()