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

后端 未结 4 2095
刺人心
刺人心 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-04 19:12

    You could use a CssSelector to get the nodes you want from the Patient element:

    from lxml.cssselect import CSSSelector
    visitSelector = CSSSelector('Visit')
    visits =  visitSelector(child)
    

    you can do the same to get the patientCode Tag and the SWOL28 tag then you can access and modifiy the text of the elements using element.text

提交回复
热议问题