# Example code:

request = container.REQUEST
RESPONSE =  request.RESPONSE

def utShowCustom(p_date):
    """ """
    try: return p_date.strftime('%Y-%m-%d')
    except: return ''

r = []
ra = r.append
ra('<?xml version="1.0" encoding="utf-8"?>')
ra('<urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">')
#mainfolders
documents = context.getCatalogedObjectsCheckView(meta_type=['Naaya Document', 'Naaya File', 'Naaya Folder'], approved=1, howmany=-1, path=['/'.join(x.getPhysicalPath()) for x in context.getMainTopics()])
for d in documents:
   ra('<url>')
   ra('<loc>%s/</loc>' % d.absolute_url())
   ra('<lastmod>%s</lastmod>' % utShowCustom(d.releasedate))
   ra('<changefreq>%s</changefreq>' % 'weekly')
   ra('</url>')

#News
news = context.getCatalogedObjectsCheckView(meta_type=['Naaya News'], approved=1)
for n in news:
   ra('<url>')
   ra('<loc>%s/</loc>' % n.absolute_url())
   ra('<lastmod>%s</lastmod>' % utShowCustom(n.releasedate))
   ra('<changefreq>%s</changefreq>' % 'daily')
   ra('</url>')
ra('</urlset>')
RESPONSE.setHeader('Content-Type', 'text/xml;charset=utf-8')
return '\n'.join(r)

#Events
news = context.getCatalogedObjectsCheckView(meta_type=['Naaya Event'], approved=1)
for n in news:
   ra('<url>')
   ra('<loc>%s/</loc>' % n.absolute_url())
   ra('<lastmod>%s</lastmod>' % utShowCustom(n.releasedate))
   ra('<changefreq>%s</changefreq>' % 'daily')
   ra('</url>')
ra('</urlset>')
RESPONSE.setHeader('Content-Type', 'text/xml;charset=utf-8')
return '\n'.join(r)
