Skip to Main Content
Learning Geospatial Analysis with Python - Third Edition
book

Learning Geospatial Analysis with Python - Third Edition

by Joel Lawhead
September 2019
Beginner content levelBeginner
456 pages
10h 53m
English
Packt Publishing
Content preview from Learning Geospatial Analysis with Python - Third Edition

Building XML using ElementTree and Minidom

Most of the time, XML can be built by concatenating strings, as you can see in the following command:

xml = "<?xml version="1.0" encoding="utf-8"?>"xml += "<kml xmlns="http://www.opengis.net/kml/2.2">"xml += " <Placemark>"xml += " <name>Office</name>"xml += " <description>Office Building</description>"xml += " <Point>"xml += " <coordinates>"xml += " -122.087461,37.422069"xml += " </coordinates>"xml += " </Point>"xml += " </Placemark>"xml += "</kml>"

However, this method can be quite prone to typos, which creates invalid XML documents. A safer way is to use an XML library. Let's build this simple KML document using ElementTree:

  1. We'll define the rootKML element and assign it a namespace.
  2. Then, we'll ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Geospatial Analysis with Python

Mastering Geospatial Analysis with Python

Silas Toms, Eric van Rees, Paul Crickard

Publisher Resources

ISBN: 9781789959277Supplemental Content