话不多说直接上代码 from xml.etree import ElementTree as ET #新文件路径与旧文件路径 NewFilePath = "D:\parseXml\\trans.xml"#新文件路径 OldFilePath = "D:\parsexml1\\trans.xml"#旧文件路径 # xml文件中的标签列表 tags =[] attr = [] # 调用递归函数生成需要的xml标签与属性值 def root(childs): for child in childs: if (child.getchildren() is None): break else: attr