改进XML比较?

时间:2016-10-21 13:11:18

标签: python xml

我有两个结构相似的xmls:

<root>
  <node1>some_name0
    <value>some_int</value>
  </node1>
  <node1>some_name1
    <value>some_float</value>
  </node1>
  <node1>some_name2
    <value>some_sting</value>
 </node1>
 <node1>some_name3
    <value>some_bool</value>
 </node1>
</root>

和第二个:

zip

如何比较具有相同名称的节点? xml1和xml2中的节点数可能不同,因此我无法使用内置的from xml.etree import ElementTree as et tr1 = et.parse(path1) root1 = tr1.getroot() tr2 = et.parse(path2) root2 = tr2.getroot() for child1 in root1.getchildren(): for child2 in root2.getchildren(): if child1.text==child2.text: for ch1, ch2 in zip(child1.getchildren(), child2.getchildren()) if ch1.tag !=ch2.tag: print "node {0} are differ from same node values {1} and {2} not equal".format(child1, ch1, ch2) break elif child2 == root2.getchildren()[-1]: print "Missed element {0} in second xml!".format(child2.text)

{{1}}

我怎样才能更漂亮,更短? 现在流程可能需要很长时间。

0 个答案:

没有答案
相关问题