I am trying to read in a simple xml file and display all the child elements all i get is the error
Traceback (most recent call last):
File "/Users/adamplowman/Documents/Uni/project/python/test_", line 10, in <module>
for element in tree:
TypeError: iteration over non-sequence
Here is the xml file
<root><child>One</child><child>Two</child></root> and this is the python file
#!/usr/bin/env python
from xml.etree import ElementTree as ET
try:
tree = ET.parse('/Users/adamplowman/Desktop/sample.xml')
except Exception, inst:
print "Unexpected error opening"
for subelement in tree:
print subelement.text if i do this within the python file
#!/usr/bin/env python
from xml.etree import ElementTree as ET
def main():
element = ET.XML("<root><child>One</child><child>Two</child></root>")
for subelement in element:
print subelement.text
if __name__ == "__main__":
# Someone is launching this directly
main() everything works fine. I am using this website for help
any help is appreciated