How to retrieve the parent node using cElementTree?

前端 未结 3 1730
鱼传尺愫
鱼传尺愫 2021-01-12 08:44

for the xml


  
     data1
  
  
     data2         


        
3条回答
  •  有刺的猬
    2021-01-12 09:02

    It seems you can get access to the parent from the child using version 1.3 of ElementTree (check http://effbot.org/zone/element-xpath.htm), by using xpath commands like child.find('../parent'). But I think python ships with version 1.2 or something.

    You should also check for lxml which is compatible with etree and has full Xpath support http://lxml.de/

提交回复
热议问题