Importing data from an external XML file

The Last.fm file also allows you to take data from their services in XML format. In this recipe, I will show you how to do this.

Getting ready

To prepare importing top tracks from Last.fm in the XML format, follow these steps:

  1. Start with the first three steps from the Getting ready section in the Importing data from an external JSON file recipe.
  2. Then, let's check the structure of the XML endpoint (http://ws.audioscrobbler.com/2.0/?method=tag.gettoptracks&tag=disco&api_key=xxx&format=xml), as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <lfm status="ok">
      <tracks tag="disco" page="1" perPage="50" totalPages="26205" total="1310249">
        <track rank="1">
          <name>Billie Jean</name> <duration>293</duration> <mbid>f980fc14-e29b-481d-ad3a-5ed9b4ab6340</mbid> ...

Get Django: Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.