我有两个具有硬结构和python脚本的xml,它们比较它们并将diff并排写入xml。像git。所有的作品,但XML并不容易,我有错误的差异。 与子节点相比,我该如何拆分,这样会更加清晰。
我的代码是
for l, r in chunk:
diff = find_diff(l, r)
batch.append(diff)
l左边是xml,r-右边。
def find_diff(l, r):
article_num = l.attrib['product-id']
diffs = find_diff_recursive(l, r)
return diffs, article_num
def find_diff_recursive(l, r):
l_string = clean(etree.tounicode(l))
r_string = clean(etree.tounicode(r))
diffs = list(difflib.ndiff(l_string.split('\n'), r_string.split('\n')))
return convert_diffs(diffs)