def parse_tei(xml):
    data = xml.split('\n')
    refs = []
    ref = []
    start = False
    title = ''
    name = ''
    date = ''
    names = []
    year = ''
    old_ref = {'title': '', 'name': '', 'date': '', 'year_pub': ''}
    for line in data:
        if (re.match('.*<date', line) and (start == False)):
            year = re.sub('.*when\\="', '', line)
            year = re.sub('".*', '', year)[0:4]
        if ((start == False) and re.match('.*<back', line)):
            start = True
        if (start == False):
            continue
        if re.match('.*<biblStruct', line):
            if (title == ''):
                continue
            ref = {'title': title, 'name': names, 'date': date, 'year_pub': year}
            if (ref['title'] == old_ref['title']):
                continue
            else:
                refs.append(ref)
                olf_ref = ref
                names = []
        if re.match('.*<title.*type="main"', line):
            title = clean(line)
        if re.match('.*<persName', line):
            forename = re.sub('<\\/forename.*', '', line)
            forename = clean(forename)
            surname = re.sub('.*<surname', '', line)
            surname = clean(surname)
            surname = re.sub('>', '. ', surname)
            name = (forename + surname)
            names.append(name)
        if re.match('.*<date', line):
            date = re.sub('.*when\\="', '', line)
            date = re.sub('".*', '', date)
            date = date[0:4]
    return refs
def parse_tei(xml):
    data = xml.split('\n')
    refs = []
    ref = []
    start = False
    title = 
    name = 
    date = 
    names = []
    year = 
    old_ref = {'title': , 'name': , 'date': , 'year_pub': }
    for line in data:
        if (re.match('.*<date', line) and (start == False)):
            year = re.sub('.*when\\="', , line)
            year = re.sub('".*', , year)[0:4]
        if ((start == False) and re.match('.*<back', line)):
            start = True
        if (start == False):
            continue
        if re.match('.*<biblStruct', line):
            if (title == ):
                continue
            ref = {'title': title, 'name': names, 'date': date, 'year_pub': year}
            if (ref['title'] == old_ref['title']):
                continue
            else:
                refs.append(ref)
                olf_ref = ref
                names = []
        if re.match('.*<title.*type="main"', line):
            title = clean(line)
        if re.match('.*<persName', line):
            forename = re.sub('<\\/forename.*', , line)
            forename = clean(forename)
            surname = re.sub('.*<surname', , line)
            surname = clean(surname)
            surname = re.sub('>', '. ', surname)
            name = (forename + surname)
            names.append(name)
        if re.match('.*<date', line):
            date = re.sub('.*when\\="', , line)
            date = re.sub('".*', , date)
            date = date[0:4]
    return refs