Python version 2.7: XML ElementTree: How to iterate through certain elements of a child element in order to find a match

后端 未结 4 2110
刺人心
刺人心 2021-01-04 19:01

I\'m a programming novice and only rarely use python so please bear with me as I try to explain what I am trying to do :)

I have the following XML:

&         


        
4条回答
  •  情书的邮戳
    2021-01-04 19:23

    This is untested by it should be fairly close to what you want.

    for patient in root:
        patient_code =  patient.find('PatientCharacteristics').find('patientCode')
        if patient_code.text == code:
                for visit in patient.find('Visits'):
                        visit_date = visit.find('VisitDate')
                        if visit_date.text == date:
                            swol28 = visit.find('DAS').find('Joints').find('SWOL28')
                            if swol28.text:
                                visit.find('DAS').find('Joints').set('SWOL28', new_swol28)
    

提交回复
热议问题