AttributeError: no such child: - Lxml objectify

3.5k views Asked by At

I am trying to extract coordinates from a KML file. However, I keep getting this error:

for e in doc.Document.Folder.Placemark:
  File "src\lxml\objectify.pyx", line 230, in lxml.objectify.ObjectifiedElement.__getattr__
  File "src\lxml\objectify.pyx", line 450, in lxml.objectify._lookupChildOrRaise
AttributeError: no such child: {http://www.opengis.net/kml/2.2}Placemark

My code for extracting the coordinates is as below:

kml_file = path.join(fileName_kml)

           with open(kml_file) as f:
               doc = parser.parse(f).getroot()
            for e in doc.Document.Folder.Placemark:
                 coor = e.Point.coordinates.text.split(',')
                 print(coor)

Not entirely sure what to do or how to fix it.

EDIT: This is the first bit of my kml file. Im also VERY new to Python so I dont really understand attritubes and children and stuff. So ansers as infformative as possible will be good thanks.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>loc</name>
    <description/>
    <Style id="poly-000000-1200-77-nodesc-normal">
      <LineStyle>

This is what the is:

 <Folder>
      <name>Untitled layer</name>
      <Placemark>
        <name>loc</name>
        <styleUrl>#poly-000000-1200-77-nodesc</styleUrl>
        <Polygon>
          <outerBoundaryIs>
            <LinearRing>
              <tessellate>1</tessellate>
              <coordinates>
                -1.0947725,53.9600505,0
                -1.0967252,53.95697,0
                -1.0909316,53.9562629,0
                -1.0887214,53.9598864,0
                -1.0947725,53.9600505,0
              </coordinates>
            </LinearRing>
          </outerBoundaryIs>
        </Polygon>
      </Placemark>
    </Folder>
0

There are 0 answers