'Removes item from parent, fixing indentation (works only with self closing items)'

def remove_from_xml(self, item):

    parent = item.getparent()
    idx = parent.index(item)
    if (idx == 0):
        if (len(parent) == 1):
            parent.text = item.tail
    else:
        parent[(idx - 1)].tail = item.tail
    parent.remove(item)
    return item
