def trycast(value):
    """
    Try to cast a string attribute from an XML tag to an integer, then to a
    float. If both fails, return the original string.
    """
    for cast in (int, float):
        try:
            return cast(value)
        except ValueError:
            continue
    return value