lxml - how to move elements into a folder based on a certain attribute
I have a KML that has a large number of placemarks, and 2 folders. How can I use etree to locate each placemark and move it into the corresponding folder. For example, the code should look for the element "SimpleData name='id'" and pick up 'Region 1', then move the whole Plaemark into the folder Area 1.
Before:
<Folder>
<name>Cluster</name>
<Folder>Area 1</Folder>
<Folder>Area 2</Folder>
<Placemark>
<styleUrl>#falseColor9</styleUrl>
<name>Customer 1</name>
<ExtendedData>
<SimpleData name="id">Region 1</SimpleData>
</ExtendedData>
</Placemark>
<Placemark>
<styleUrl>#falseColor8</styleUrl>
<name>Customer 1</name>
<ExtendedData>
<SimpleData name="id">Region 2</SimpleData>
</ExtendedData>
</Placemark>
</Folder>
After:
<Folder>
<name>Cluster</name>
<Folder>Area 1</Folder>
<Placemark>
<name>Customer 1</name>
<styleUrl>#falseColor9</styleUrl>
<ExtendedData>
<SimpleData name="id">Region 1</SimpleData>
</ExtendedData>
</Placemark>
<Folder>Area 2</Folder>
<Placemark>
<styleUrl>#falseColor8</styleUrl>
<name>Customer 1</name>
<ExtendedData>
<SimpleData name="id">Region 2</SimpleData>
</ExtendedData>
</Placemark>
</Folder>
Any help would be much appreciated.
from Recent Questions - Stack Overflow https://ift.tt/3mQLF7l
https://ift.tt/eA8V8J
Comments
Post a Comment