[Answered ]-How do i check for specific element value before reading this xml – django python

1👍

datei = ET.parse(settings.MEDIA_ROOT+'\\table.xml')
datas = datei.getroot()

for info in datas.findall('info'):
    if info.find('Country').text == 'GERMANY':
        # do whatever
        pass

For more advanced stuff just read the docs at http://docs.python.org/2/library/xml.etree.elementtree.html

1👍

If you just want to know that the file contains <Country>GERMANY</Country>, a shorter version is:

if any(i.find('Country').text == 'GERMANY' for i in datas.iterfind('info')):
   print('Found It!')

Leave a comment