<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_string(self):
 """Convert SitemapIndex into a string."""

        root = etree.Element('sitemapindex', nsmap={None: SITEMAP_NS})
        for sitemap in self.sitemaps:
            sm = etree.SubElement(root, 'sitemap')
            etree.SubElement(sm, 'loc').text = sitemap.url
            if hasattr(sitemap.lastmod, 'strftime'):
                etree.SubElement(sm, 'lastmod').text = \
                    sitemap.lastmod.strftime('%Y-%m-%d')
            elif isinstance(sitemap.lastmod, str):
                etree.SubElement(sm, 'lastmod').text = sitemap.lastmod
        return etree.tostring(root, pretty_print=True, xml_declaration=True,
                              encoding='utf-8')