'Builds a S3XML tree from a list of elements
@param elements: list of <resource> elements
@param root: the root element to link the tree to
@param domain: name of the current domain
@param url: url of the request
@param start: the start record (in server-side pagination)
@param limit: the page size (in server-side pagination)
@param results: number of total available results
@param maxbounds: include maximum Geo-boundaries (lat/lon min/max)'

def tree(self, elements, root=None, domain=None, url=None, start=None, limit=None, results=None, maxbounds=False):

    ATTRIBUTE = self.ATTRIBUTE
    success = False
    if (root is None):
        root = etree.Element(self.TAG.root)
    if ((elements is not None) or len(root)):
        success = True
    set_attribute = root.set
    set_attribute(ATTRIBUTE.success, json.dumps(success))
    if (start is not None):
        set_attribute(ATTRIBUTE.start, str(start))
    if (limit is not None):
        set_attribute(ATTRIBUTE.limit, str(limit))
    if (results is not None):
        set_attribute(ATTRIBUTE.results, str(results))
    if (elements is not None):
        root.extend(elements)
    if domain:
        set_attribute(ATTRIBUTE.domain, self.domain)
    if url:
        set_attribute(ATTRIBUTE.url, current.response.s3.base_url)
    if maxbounds:
        bounds = current.gis.get_bounds()
        set_attribute(ATTRIBUTE.latmin, str(bounds['lat_min']))
        set_attribute(ATTRIBUTE.latmax, str(bounds['lat_max']))
        set_attribute(ATTRIBUTE.lonmin, str(bounds['lon_min']))
        set_attribute(ATTRIBUTE.lonmax, str(bounds['lon_max']))
    return etree.ElementTree(root)
