Returns the specified attribute from the XML element, raising a ValueError
    if it is not availaible.
    
    :arg xml: the XMLElement instance to get the attribute from.
    :arg name: the name of the attribute in xml.attrib dictionary.
    :arg tag: the name of the tag to display with the ValueError if the attribute is missing.

def get_attrib(xml, name, tag=None, cast=str, default=None):
    """Returns the specified attribute from the XML element, raising a ValueError
    if it is not availaible.
    
    :arg xml: the XMLElement instance to get the attribute from.
    :arg name: the name of the attribute in xml.attrib dictionary.
    :arg tag: the name of the tag to display with the ValueError if the attribute is missing.
    """
    if name in xml.attrib:
        return cast(xml.attrib[name])
    elif default is not None:
        return default
    elif tag is not None:
        raise ValueError("'{}' is a required attribute of <{}> tag.".format(name, tag))