I have parsed XML file looking like this. Maybe I just didn't copy well,but it's ok, so, here it is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE raml SYSTEM 'raml20.dtd'>
<raml version="2.0" xmlns="raml20.xsd">
<cmData type="actual">
<managedObject class="LN" distName="PTR" id="2425">
<p name="aak">220</p>
<p name="orp">05</p>
<p name="name">Portro</p>
<p name="optres">false</p>
<p name="optblu">false</p>
<p name="aoptdet">false</p>
<p name="advcell">false</p>
<list name="sibList">
<item>
<p name="sibcity">177</p>
<p name="sibrep">2</p>
</item>
<item>
<p name="sibcity">177</p>
<p name="sibrep">1</p>
</item>
</list>
</managedObject>
<managedObject class="LN" distName="KRNS" id="93886">
<p name="aak">150</p>
<p name="orp">05</p>
<p name="name">Portro</p>
<p name="optres">false</p>
<p name="optblu">tru</p>
<p name="aoptdet">false</p>
<p name="advcell">true</p>
<list name="sibList">
<item>
<p name="sibcity">177</p>
<p name="sibrep">1</p>
</item>
<item>
<p name="sibcity">180</p>
<p name="sibrep">2</p>
</item>
</list>
</managedObject>
....
<managedObject>
...
</managedObject>
...
</cmData>
</raml>
I need to go through all "managedObject" and compare every parameter(p name) from first managedObject with parameters (aak, orp, etc.) from another managedObjects, and get output of different parameters and values of them, if there is no different values of parameters, do nothing. I wrote code for comparasion, but I don't know how to go through list (it's named "sibList") and compare parameters. I wrote this function, where key is "p name" and value is value of "p name":
temp = []
for i in temp_ln:
for j, k in zip(i.getchildren(), i):
temp.append([i.get('distName'), j.get('name'), j.text])
tempdict = {}
for i in temp_ln:
td = {}
for j in i.getchildren():
td.update({j.get('name'): j.text})
tempdict.update({i.get('distName'): td})
elements_list = {}
if j.get('name') == 'sibList':
for item in j.getchildren():
for w in item.getchildren():
elements_list.update({ w.get('name'): w.text})
main_dif = {}
for key, value in tempdict.iteritems():
dif_k = {}
for k, v in value.iteritems():
try:
a = ref[k]
except:
a = None
if v != a:
if k == 'name':
pass
else:
dif_k.update({k:(v, a)})
main_dif.update({key:dif_k})
managedObjectnodes? Have you triedlxmlorBeautifulSoup?{}button to format the code block.