I have two xmls with similar structure:
<root>
<node>some_name0
<value>some_int</value>
</node>
<node>some_name1
<value>some_float</value>
</node>
<node>some_name2
<value>some_sting</value>
</node>
<node>some_name3
<value>some_bool</value>
</node>
</root>
and second one:
<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>
How can I compare nodes with same names?
The numbers of nodes in xml1 and xml2 can differ, so I cannot use the zip
built-in.
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)
How can I do it prettier and shorter? Right now process can take a long time.