Reputation: 111
I'm getting an error from the following code:
import xml.etree.ElementTree as ET
tree = ET.ElementTree()
root = ET.Element("configuration")
elem = ET.SubElement(root, "appConfig")
elem2 = ET.SubElement(root, "fileGDB")
print ET.tostring(root)
tree.write(sys.stdout)
It throws an exception on the following line in the ElementTree.py module: iterate = elem.getiterator # cET compatibility The exception is: AttributeError: 'NoneType' object has no attribute 'getiterator'
In the code above:
print ET.tostring(root)
prints out just fine. I don't understand why it's throwing this exception. What am I doing wrong?
Steve
Upvotes: 3
Views: 1873
Reputation: 111
Okay duh, I needed to make the following line the last after creating nodes:
tree = ET.ElementTree(root)
Maybe someone else will be as numbskull as I was. :-)
Upvotes: 6