def to_string(self):
        """" Recursively converts nodes and children to text string. """
        s = attrs = ""
        for item in self.attrs.items():
            if attrs != "":
                attrs += " "
            attrs += '%s="%s"' % (item[0], item[1])
        
        if self.children or self.text or str.isspace(self.text):
            if attrs:
                s += '\n<%s %s>' % (self.tag, attrs) 
            else:
                s += '\n<%s>' % (self.tag) 
                
            s += self.text
            for node in self.children:
                s += node.to_string()
            s += '</%s>\n' % self.tag
        else:
            if attrs:
                attrs = " " + attrs
            s += "<%s%s/>\n" % (self.tag, attrs)
        s = s.replace('\n\n', '\n')
        return s
" Recursively converts nodes and children to text string. 
recipes/Python/579133_MicroXml_Standalone_library_basic_XML/recipe-579133.py