Example: Export Taxonomy terms (tags) as an XML file

Last updated on
30 April 2025

Step-by-step instructions on how to use Views Data Export (version 6.x-2.0-beta6) to export tags (taxonomy terms) into an XML file. This can help you migrate your tags from a Drupal 6 site into a site running a newer version of Drupal. If you don't want to read through all the instructions, see the attached sample Views Import code that you can use to automatically create this View (although you will need to change the User Roles and Vocabulary to match roles and vocabularies on your site).

Initial settings for a View that exports taxonomy terms

After you decide to "Add" a new view (at admin/build/views/add ), below are the recommended settings for fields on the first screen when exporting taxonomy terms. This assumes you arel only exporting ONE vocabulary at a time (for example, Vocabulary1 could be "Blog Categories", and then Vocabulary2 might be "Office Departments").

  • View name: all_export_terms_vocabulary1 (I like my export views to show up at the top of my Views list, so I start the machine name with the word "all".)
  • Human readable name: Export Vocabulary1 tags
  • View description: Export all tags from Vocabulary1 as XML file
  • View tag: migrate (This OPTIONAL tag is how I organize my views, so that I can easily find those I'm using to migrate content.)
  • View type: Term

Tips about Live Preview and Saving

As a general rule, I recommend two good habits when editing Views. First, in your general Views settings (under "Tools" at admin/build/views/tools) check the box for "Disable automatic live preview". The Live Preview can cause JavaScript-related slowness and errors that are annoying. I also recommend that you click on the "Save" button after every change you make to each specific View, so that you don't lose your settings.

Default Settings

Here are the settings you need on the "Defaults" screen.

Basic Settings

Under the "Basic Settings" heading, make the following changes.

  • Change "Access" from "Unrestricted" to "Role" and then check only "Administrator" (or whatever name you've given to this role on your site), as you may not want to reveal all of this to the universe.
  • Change "Use pager" from "Paged, 10 items" to "Display all items" (leave the Offset at the default number of "0").
  • Remember to click on "Save" and then, after waiting for the Save message at the top of the page (such as "The view Export all Vocabulary1 tags has been saved.").

Filters

  • Choose the plus symbol to "Add" a filter that will limit the tags you export to only one vocabulary.
  • Choose "Taxonomy: Vocabulary" and click on "Add".
  • Leave "Operator" as "Is one of" and, under "Options", check the box next to your vocabulary, such as "Blog Topics".
  • You can even add an "Administrative Title" that explains what this filter does, like "Limit to Blog Topics".
  • Click on "Update".
  • Remember to click on "Save" and then wait for the Save message at the top of the page.

Fields, part 1

Under "Fields", here are the recommended tag-related settings.

  • Choose the plus symbol to "Add" a field you want to export.
  • If you have a lot of fields on your site, you may want to choose "Taxonomy" from the drop-down menu under "Groups" so you can limit the number of fields you need to look through.
  • Check the boxes next to "Taxonomy: Term" and also next to "Taxonomy: Weight" and click on "Add".
Configure Term field

Now you need to decide how this tag's name (such as "Drupal") will be displayed. Below are the recommended settings for fields under "Defaults: Configure field Taxonomy: Term".

  • Administrative Title: Tag Name
  • Label: Name
  • Click "Update".
Configure Weight field

Now you need to decide how this tag's weight, or order in relation to other tags, will be displayed. Below are the recommended settings for fields under "Defaults: Configure field Taxonomy: Weight".

  • Administrative Title: Tag Weight
  • Label: Leave this as "Weight"
  • Click "Update".

Remember to click on "Save" and then wait for the Save message at the top of the page.

Relationships

Next, under "Relationships", click on the plus symbol (or "Add"). This will let you connect each tag to its parent, so that you can export the relationships and hierarchy of your tags.

  • Choose "Taxonomy: Parent term" and click on "Add".
  • Add "Parent" as the "Administrative Title" and click on "Update".
  • Remember to click on "Save" and then wait for the Save message at the top of the page.

Fields, part 2

Under "Fields", here are the recommended parent tag-related settings. You must first create the relationship between a tag and its parent tag (as we did in a previous step), before you can add these parent tag fields.

  • Choose the plus symbol to "Add" a field you want to export.
  • If you have a lot of fields on your site, you may want to choose "Taxonomy" from the drop-down menu under "Groups" so you can limit the number of fields you need to look through.
  • Check the boxes next to "Taxonomy: Term" and also next to "Taxonomy: Weight" and click on "Add".
Configure Parent Term field

Now you need to decide how this tag's name (such as "Drupal") will be displayed. Below are the recommended settings for fields under "Defaults: Configure field Taxonomy: Term".

  • Relationship: Parent
  • Administrative Title: Parent Tag Name
  • Label: ParentName (I do not use spaces in this Label, so that it will export to XML more easily.)
  • Click "Update".
Configure Parent Weight field

Now you need to decide how this parent tag's weight, or order in relation to other tags, will be displayed. Below are the recommended settings for fields under "Defaults: Configure field Taxonomy: Weight".

  • Relationship: Parent
  • Administrative Title: Parent Tag Weight
  • Label: ParentWeight
  • Click "Update".

Remember to click on "Save" and then wait for the Save message at the top of the page.

Sort criteria

Next, under "Sort criteria", click on the plus symbol (or "Add"). This will let decide which tags show at the top of your exported list of tags. This is important because you want to import parent tags first, so that they exist when their children tags attempt to connect to them during the import process.

  • Check the box next to "Taxonomy: Term ID" and click on "Add".
  • Relationship: choose "Parent" from the drop-down list.
  • Administrative Title: enter "ParentTermID" (again, I don't use spaces in this Label).
  • Leave the default sort of "Sort ascending" and click "Update".
  • Remember to click on "Save" and then wait for the Save message at the top of the page.

Add XML display

Underneath the top left of the screen, where you read "Defaults", there is also a drop-down list. Choose "Data export" from this list and then click on the "Add display" button underneath it. This lets us make specific configurations for XML, so that our file of exported tags works correctly. Here are recommended settings for the "Data export" screen.

Basic Settings

Under the "Basic Settings" heading, make the following changes.

  • Machine Name: change from "views_data_export_1" to "all_export_terms_vocabulary1_xml"
  • Name: change from "Data export" to "XML".
  • Items to display: change from "10 items" to "Display all items" (leave the Offset at the default number of "0") and choose "Update default display".
  • Remember to click on "Save" and then wait for the Save message at the top of the page. For now, ignore the error message that says "Display "XML" uses a path but the path is undefined."

Style Settings

After this Save completes, click again on the newly-named display at the top left called "XML." Then, under the "Style Settings" heading, choose the following settings.

  • Click on "CSV file" and choose "XML file" instead. After you choose "Update", choose the following settings under "XML: Style options".
  • Check "Provide as file". (If you download the file of all your tags, you don't have to worry about any slow networks or permissions issues when you are trying to import it into a new site.)
  • Filename: "export-terms-vocabulary1-%timestamp-full.xml" (This gives a clear name, which will end in a slightly different timestamp each time you download your file.)
  • Click "Update".
  • Remember to click on "Save" and then wait for the Save message at the top of the page.

Data export settings

After this Save completes, click again on the "XML" display at the top left. Then, under the "Data export settings" heading, choose the following settings.

  • Path: change from "None" to "export/terms/vocabulary1/xml".
  • Click "Update".
  • Remember to click on "Save" and then wait for the Save message at the top of the page.

Download and Test your Tag export file

Visit the path you created and download this file, for example: http://mysite.com/export/terms/vocabulary1/xml. If you open this file, you will probably see code that looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<term_datas>
  <term_data>
    <Name>drupal</Name>
    <Weight>0</Weight>
    <ParentName></ParentName>
    <ParentWeight>0</ParentWeight>
  </term_data>
  <term_data>
    <Name>libraries</Name>
    <Weight>0</Weight>
    <ParentName></ParentName>
    <ParentWeight>0</ParentWeight>
  </term_data>
</term_datas>

Help improve this page

Page status: Not set

You can: