tei.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:tools 作者: freedict 项目源码 文件源码
def attach_xml_body(tei_file, xml_entries):
    """Read given TEI XML file until the body tag. From there, insert the given
    entries. The result is a full TEI XML structure."""
    events = ET.iterparse(tei_file, events=["start"])
    root = next(events)[1]
    for _, elem in events:
        if elem.tag == 'body':
            break

    text = next(n for n in root if n.tag.endswith('text'))
    text.clear() # throw away all potential content
    body = ET.SubElement(text, 'body')
    for entry in xml_entries:
        body.append(entry)
    ET.register_namespace('', 'http://www.tei-c.org/ns/1.0')
    return ET.ElementTree(root)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号