I'd like to use getparent() in some code I'm working on to read XML files. When I try what's below I get this error: AttributeError: getparent
I assume I'm making a basic mistake but after an hour of searching and trial and error, I can't figure out what it is. (Using python 2.7 if that matters)
import xml.etree.cElementTree as ET import lxml.etree url = [file.xml] tree = ET.ElementTree(file=url) txt = 'texthere' for elem in tree.iter(tag='text'): print elem.text print elem.getparent()
No comments:
Post a Comment