def generate(self, root_element=None):
        """Create <url> element under root_element."""
        if root_element is not None:
            url = etree.SubElement(root_element, 'url')
        else:
            url = etree.Element('url')
        etree.SubElement(url, 'loc').text = self.loc
        if self.lastmod:
            if hasattr(self.lastmod, 'strftime'):
                etree.SubElement(url, 'lastmod').text = \
                    self.lastmod.strftime('%Y-%m-%d')
            elif isinstance(self.lastmod, str):
                etree.SubElement(url, 'lastmod').text = self.lastmod
        if self.changefreq and self.changefreq in self.freq_values:
            etree.SubElement(url, 'changefreq').text = self.changefreq
        if self.priority and 0.0 <= self.priority <= 1.0:
            etree.SubElement(url, 'priority').text = str(self.priority)
        return url