0
我想用lxml打開一個xml文件,編輯xml,然後保存出不同的版本,但我無法得到它的工作。第一次保存是爲了刪除該部分,但第二次保存是爲了讓他們進入,目前保存1正確刪除部分,但保存2,這意味着將其留在。我做錯了什麼?下面是一個代碼示例:Python lxml - 創建樹的不同叉形
from lxml import etree
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(pathToXmlFile, parser)
root = tree.getroot()
etree1 = etree
tree1 = tree
etree1.strip_elements(tree1, 'products')
tree1.write(pathToXmlFileOut1, pretty_print = True, xml_declaration = True, encoding = 'UTF-8')
etree2 = etree
tree2 = tree
tree2.write(pathToXmlFileOut2, pretty_print = True, xml_declaration = True, encoding = 'UTF-8')
謝謝,使用tree1 = copy.deepcopy(tree)它工作的一種享受。 – speedyrazor 2014-11-05 06:19:22