0

I have parsed XML file looking like this:

   <?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>
    </menagedObject>
    ....
    <menagedObject>
    ...
    </menagedObject>
    ...
</cmData>
</raml>

I need to go through all menagedObject and compare all parametars(p name). I wrote code for comparasion, but I don't know how to go through list and compare parametars. 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})

        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})
5
  • Your XML file is not well-formed. Do you have 1 XML file or a list of files? Commented Mar 6, 2017 at 20:07
  • What do you mean by compare parameters? Commented Mar 6, 2017 at 20:09
  • We can not reproduce your problem since your code fragment is not complete. Can you give us more? Any stacktrace? Commented Mar 6, 2017 at 20:10
  • I have one xml file, and yes, is now well-formed, i made a mistake when I posting quastion. But that is not really important, I just need go through list. Parameters are "aak", "orp" etc. I'm going to edit my quastion and add some code Commented Mar 6, 2017 at 20:25
  • Possible duplicate of Python function for xml list Commented Mar 14, 2017 at 13:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.