Aug-27-2020, 07:53 PM
Hello,
The documentation on the PyKML site is a bit sparse for newbies, and I'm having two issues:
1. I need to loop through all the Placemark blocks, possibly adding a new element in case I find a certain element within that current block… but this code only displays the first block, and stops;
2. How can I prevent PyKML from prepending the namespace stuff, and keep it clean?
Thank you.
The documentation on the PyKML site is a bit sparse for newbies, and I'm having two issues:
1. I need to loop through all the Placemark blocks, possibly adding a new element in case I find a certain element within that current block… but this code only displays the first block, and stops;
2. How can I prevent PyKML from prepending the namespace stuff, and keep it clean?
Thank you.
from pykml import parser from lxml import etree with open("input.kml") as f: doc = parser.parse(f) root = doc.getroot() Placemark = root.Document.Placemark for pm in Placemark.getchildren(): print(pm.tag, pm.getparent().tag) """ {http://www.opengis.net/kml/2.2}name {http://www.opengis.net/kml/2.2}Placemark {http://www.opengis.net/kml/2.2}styleUrl {http://www.opengis.net/kml/2.2}Placemark {http://www.opengis.net/kml/2.2}Point {http://www.opengis.net/kml/2.2}Placemark """