How to check if the sitemap contain some urls
Question: I am new to python and django, I am trying to fix a sitemap creator and one of
the bugs that it would create an empty sitemap. Meaning the sitemap does not
really have any urls in it.

example:

    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    </urlset>
    

I would like to know the best approach to check if the sitemap have an empty
urlset tag or not.

Thanks


Answer: You could use
[`ElementTree`](http://docs.python.org/2/library/xml.etree.elementtree.html)
to parse xml:

    
    
    from xml.etree import ElementTree as etree
    
    urlset = etree.fromstring(xml)
    if urlset.find('url') is None:
       print("sitemap has no urls") 
    

