简体   繁体   中英

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.

The tree itself has no getchildren() method.

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

Note that getchildren() is deprecated. See the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM