Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python For loop display previous value if correct one match with XML

right now i have this XML

I need to get 1 value ("enabled") behind the correct one i get.

this is the code im using

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

def checktap(text):
  nodes = minidom.parse("file.xml").getElementsByTagName("node")
  for node in nodes:
      if node.getAttribute("text") == text:

          if node.getAttribute("enabled") == True:
              return ("Yes")
          else:
              return ("No")       


value = checktap("EU 39")
print(value)
    

with this code, i’ll get the exact node im searching, and the value is enabled=True, but i need to get the one behind this (android.widget.LinearLayout) with the value enabled=False

>Solution :

You can use itertools.pairwise

from itertools import pairwise

def checktap(text):
    nodes = minidom.parse("file.xml").getElementsByTagName("node")
    for node1, node2 in pairwise(nodes):
        if node2.getAttribute("text") == text and node2.getAttribute("enabled"):
            return True
    return False
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading