intrigued_66
intrigued_66

Reputation: 17220

Python getchildren() not working for valid XML tree

If I run the following python on an XML file (see bottom of Q):

import xml.etree.ElementTree as ET
tree = ET.parse('C:\\temp\\test2.xml')
print(tree.getchildren())

I get the error:

AttributeError: 'ElementTree' object has no attribute 'getchildren'

I uploaded the XML to an online validator and it said the XML was fine.

Upvotes: 3

Views: 8603

Answers (2)

Chithkala
Chithkala

Reputation: 51

getchildren() is deprecated.

So use list(elem), in your case use list(tree.getroot())

Upvotes: 5

Jim Garrison
Jim Garrison

Reputation: 86754

The tree itself has no getchildren() method.

print(tree.getroot().getchildren())

Note that getchildren() is deprecated. See the documentation

Upvotes: 4

Related Questions