def updateAttributes(elem, dict, update=True):
    """
    Update the properties of the given elem to
    be those in dict. If update is False, don't
    change existing properties, only add new ones.
    Does not remove any properties.
    The properties need not be strings, so long as str()
    works on them.
    """
    for k, v, in list(dict.items()):
        if update or k not in elem.attrib:
            elem.set(k, str(v))
    return elem