Python Forum
[PyKML] Loop through all Placemarks; Remove namespace
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyKML] Loop through all Placemarks; Remove namespace
#1
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.

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
	"""
Reply
#2
I think if you are interested in this package you should contact the author Tyler Erikson.
His email address is posted on the pypi.org site here: https://pypi.org/project/pykml/
Reply
#3
Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  'namespace' shorthand for function arguments? shadowphile 5 2,611 Aug-11-2021, 09:02 PM
Last Post: shadowphile
  python multiprocessing import Pool, cpu_count: causes forever loop | help to remove Hassibayub 0 1,875 Jun-18-2020, 05:27 PM
Last Post: Hassibayub
  [pykml] "AttributeError: 'lxml.etree._ElementTree' object has no attribute 'Document' Winfried 3 6,606 May-26-2020, 09:30 PM
Last Post: Winfried
  Beginner question: lxml's findall in an xml namespace aecklers 0 2,927 Jan-22-2020, 10:53 AM
Last Post: aecklers
  Namespace and scope difference Uchikago 9 4,627 Jul-03-2019, 03:36 PM
Last Post: Uchikago
  global namespace of an imported function (2 Qs) Skaperen 4 3,273 Oct-09-2018, 12:30 AM
Last Post: Skaperen
  Namespace Packages jmj1970 0 3,122 Sep-30-2017, 03:13 PM
Last Post: jmj1970
  local namespace vs. global namespace Skaperen 13 9,900 Jul-02-2017, 11:30 AM
Last Post: DeaD_EyE
  python import module or namespace from namepsace variable ? harun2525 11 8,673 May-23-2017, 05:39 PM
Last Post: Larz60+
  AttributeError: 'Namespace' object has no attribute 'brokeName' kikilalongue 4 24,523 May-22-2017, 12:00 PM
Last Post: kikilalongue

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020