Elementtree findall fails with attributes in root

المشرف العام

Administrator
طاقم الإدارة
I am trying to parse a KML file using Python's ElementTree module. It appears that the attributes in the element cause these lines to report zero:

import xml.etree.ElementTree as ET pathToKML = r"L:\path\to\my.kml" root = ET.ElementTree(file=pathToKML) lstPlacemark = root.findall("./Document/Folder/Placemark") print len(lstPlacemark)

The KML attributes are:



If I take out the attributes the findall works.

I have been able to find the path to the placemarks thanks to PyScripter's debugger. This works:

lstPlacemark = root._root._children[0]._children[3]._children print len(lstPlacemark)

...but might be incomprehensible to the next programmer. Has anyone had this problem with ElementTree? Any way to use findall?

Thanks



أكثر...
 
أعلى