📜  python 按标签拆分大型 xml 文件 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:45.926000             🧑  作者: Mango

代码示例1
import xml.etree.ElementTree as ET
context = ET.iterparse('file.xml', events=('start' , 'end' ))
for event, elem in context:
    if elem.tag == 'row':
        title = elem.find('NAME').text
        filename = format(title + ".xml")
        with open(filename, 'wb') as f:
            f.write("\n")
            f.write(ET.tostring(elem))