'SAX XML logic for parsing new element found.'

def endElement(self, name, value, connection):

    if (name == CORS_CONFIG):
        self.validateParseLevel(name, 1)
        self.parse_level -= 1
    elif (name == CORS):
        self.validateParseLevel(name, 2)
        self.parse_level -= 1
        self.cors.append(self.collections)
        self.collections = []
    elif (name in self.legal_collections):
        self.validateParseLevel(name, 3)
        if (name != self.collection):
            raise InvalidCorsError(('Mismatched    start    and    end    tags    (%s/%s)' % (self.collection, name)))
        self.parse_level -= 1
        if (not self.legal_collections[name]):
            self.collections.append((name, value.strip()))
        else:
            self.collections.append((name, self.elements))
        self.elements = []
        self.collection = None
    elif (name in self.legal_elements):
        self.validateParseLevel(name, 3)
        if (self.collection is None):
            raise InvalidCorsError(('Tag    %s    found    outside    collection' % name))
        if (name not in self.legal_collections[self.collection]):
            raise InvalidCorsError(('Tag    %s    not    allowed    in    %s    collection' % (name, self.collection)))
        if (name != self.element):
            raise InvalidCorsError(('Mismatched    start    and    end    tags    (%s/%s)' % (self.element, name)))
        self.elements.append((name, value.strip()))
        self.element = None
    else:
        raise InvalidCorsError(('Unsupported    end    tag    ' + name))
