Hello,
Does someone know how to use pykml/lxml to remove a node?
I simply need to remove all occurences of "ExtentedData" nodes from a KML file, but this does nothing:
Input file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<name>KML Samples</name>
<Folder>
<name>Paths</name>
<Placemark>
<name>Tessellated</name>
<ExtendedData>
…
</ExtendedData>
</Placemark>
</Folder>
</Document>
</kml>
It's because pykml prepends "{http://earth.google.com/kml/2.0}" to each tag:
{http://earth.google.com/kml/2.0}name
{http://earth.google.com/kml/2.0}visibility
{http://earth.google.com/kml/2.0}description
{http://earth.google.com/kml/2.0}ExtendedData
{http://earth.google.com/kml/2.0}LineString
Is there a way to prevent it from doing so?
Does someone know how to use pykml/lxml to remove a node?
I simply need to remove all occurences of "ExtentedData" nodes from a KML file, but this does nothing:
from lxml import etree from pykml import parser with open("input.kml") as f: doc = parser.parse(f) root = doc.getroot() folder = root.Document.Folder.Placemark for pm in folder.getchildren(): if pm.tag=="ExtendedData": folder.remove(pm) outfile = open("output.kml","wb") outfile.write(etree.tostring(doc, pretty_print=True))Thank you.
Input file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<name>KML Samples</name>
<Folder>
<name>Paths</name>
<Placemark>
<name>Tessellated</name>
<ExtendedData>
…
</ExtendedData>
</Placemark>
</Folder>
</Document>
</kml>
It's because pykml prepends "{http://earth.google.com/kml/2.0}" to each tag:
for pm in folder.getchildren(): #How to forbid pykml to prepend {http://earth.google.com/kml/2.0} ? print(pm.tag) #if pm.tag=="ExtendedData": if pm.tag=="{http://earth.google.com/kml/2.0}ExtendedData": folder.remove(pm)C:\>myscript.py input.kml
{http://earth.google.com/kml/2.0}name
{http://earth.google.com/kml/2.0}visibility
{http://earth.google.com/kml/2.0}description
{http://earth.google.com/kml/2.0}ExtendedData
{http://earth.google.com/kml/2.0}LineString
Is there a way to prevent it from doing so?