elementtree

ElementTree Returns Element Instead of ElementTree

一曲冷凌霜 提交于 2020-07-17 08:27:32
问题 I am trying to build an ElementTree from a string. When I do the following (as set out in Python ElementTree: Parsing a string and getting ElementTree instance), I get an Element instead of an ElementTree : companyTree = ElementTree.ElementTree(ElementTree.fromstring('<companies></companies>')) If I do print(companyTree.getroot()) I get AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getroot' In other words, companyTree is an Element instead of an ElementTree .