def xml_subelement_attr(xml_elem, subelement, convert=None, attribute=
    'value', default=None, quiet=False):
    """
    Search for a sub-element and return the value of its attribute.

    For the following XML document:

    .. code-block:: xml

        <xml_elem>
            <subelement value="THIS" />
        </xml_elem>

    a call to ``xml_subelement_attr(xml_elem, "subelement")`` would return ``"THIS"``


    :param xml_elem: search the children nodes of this element
    :param subelement: Name of the sub-element to search for
    :param convert: if not None, a callable to perform the conversion of this attribute to a certain object type
    :param attribute: name of the attribute to get
    :param default: default value if the subelement or attribute is not found
    :param quiet: if True, don't raise exception from conversions, return default instead
    :return: value of the attribute or ``None`` in error cases

    """
    if xml_elem is None or not subelement:
        return None
    subel = xml_elem.find(subelement)
    if subel is None:
        value = default
    else:
        value = subel.attrib.get(attribute)
        if value is None:
            value = default
        elif convert:
            try:
                value = convert(value)
            except:
                if quiet:
                    value = default
                else:
                    raise
    return value
