'Inserts the node newChild before the existing child node refChild.
If refChild is null, insert newChild at the end of the list of children.'

def insertBefore(self, newChild, refChild):

    if (newChild.nodeType not in self._child_node_types):
        raise IllegalChild(('%s    cannot    be    child    of    %s' % (newChild.tagName, self.tagName)))
    if (newChild.parentNode is not None):
        newChild.parentNode.removeChild(newChild)
    if (refChild is None):
        self.appendChild(newChild)
    else:
        try:
            index = self.childNodes.index(refChild)
        except ValueError:
            raise xml.dom.NotFoundErr()
        self.childNodes.insert(index, newChild)
        newChild.nextSibling = refChild
        refChild.previousSibling = newChild
        if index:
            node = self.childNodes[(index - 1)]
            node.nextSibling = newChild
            newChild.previousSibling = node
        else:
            newChild.previousSibling = None
        newChild.parentNode = self
    return newChild
