@classmethod
def replace_with_contents(c, elem):
    """removes an element and leaves its contents in its place. Namespaces supported."""
    parent = elem.getparent()
    index = parent.index(elem)
    children = elem.getchildren()
    previous = elem.getprevious()
    if index == 0:
        parent.text = (parent.text or '') + (elem.text or '')
    else:
        previous.tail = (previous.tail or '') + (elem.text or '')
    for child in children:
        parent.insert(index + children.index(child), child)
    if len(children) > 0:
        last_child = children[-1]
        last_child.tail = (last_child.tail or '') + (elem.tail or '')
    elif index == 0:
        parent.text = (parent.text or '') + (elem.tail or '')
    else:
        previous.tail = (previous.tail or '') + (elem.tail or '')
    parent.remove(elem)
