lxml将元素附加到不同的fi

2024-09-29 22:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个文件要合并。我试图捕获特定的元素,并将它们附加到另一个xml文件的末尾。到目前为止我得到了这个。。在

from lxml import etree



parser = etree.XMLParser(remove_blank_text=True)

filename = "/Users/eeamesX/work/data/xmltest/output.xml"
tree = etree.parse(filename, parser)
etree.tostring(tree)

root = tree.getroot()

etree.tostring(root)

allTranscripts = root.findall(".//Speaker")
allTranscripts2 = root.findall(".//Device")


for t in allTranscripts:
    print etree.tostring(t)

for e in allTranscripts2:
    print etree.tostring(e)

现在,我想使用这个从file1.xml获取数据,并将数据添加到file2.xml的末尾。有什么帮助吗!?在


Tags: 文件intreeparserforrootxmlfilename

热门问题