From the course: Effective Serialization with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: ETL from XML to database

Solution: ETL from XML to database - Python Tutorial

From the course: Effective Serialization with Python

Start my 1-month free trial

Solution: ETL from XML to database

(upbeat music) - We start by writing the schema definition. So we create a table called records, with a time column which is a timestamp. With latitude and longitude columns, which are double or float in Python and the shape which is a VARCHAR of 128, meaning a string of two, 128 characters. And now let's look at the ETL. So if we import sqlite3 and we import ElemenTree. And the insert_sql is that we want to insert to the records, the values and we specify four values. And here's the ETL function. We connect to the database, we load the schema from the file and we execute script to create a table in the database. Now we're going over the XML file and we keep account of the number of records. For every element in the siting elements, we find the time and convert it to a timestamp. Then you find the latitude and longitude elements and convert them to float. And the shape is a text, so we don't need to convert it to…

Contents