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(root.getroot())      I get
AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'getroot'
In other words, companyTree is an Element instead of an ElementTree. According to the accepted answer in 1, I should be getting an ElementTree. Has the API changed? How do I get an ElementTree from a string now? Thanks.
Note that there is more on this problem in Python ElementTree: ElementTree vs root Element
No comments:
Post a Comment