This module allows to import/export taxonomies, structures or simple lists of terms into/from a vocabulary from/to a CSV file, a url or a copy-and-paste text.

Csv format is a simple list of values separated by a delimiter, often comma (,) or semicolon (;), and enclosures, often quotation marks ("). If you are unsure how to create a CSV file, you might want to use OpenOffice Calc or another spreadsheet application to export your data into a CSV file.

Table of Contents

  1. Formats
    1. Alone terms
    2. Full term fields and links
    3. Terms (flat vocabulary)
    4. Hierarchical tree structure or one term by line structure
    5. Polyhierarchical structure
    6. First level parents
    7. First level children
    8. Related terms
    9. Full term definitions
    10. Term descriptions
    11. Term weights
    12. Synonyms terms
    13. Taxonomy manager
  2. Import
    1. What to import (content of the source)?
    2. Where are terms to import?
    3. Where to import into (vocabulary destination)?
    4. How to import your terms?
    5. Big taxonomies import
  3. Export
  4. Taxonomy csv import API
  5. Advanced settings and hints
    1. Delimiters and enclosures
    2. Permissions
    3. Other hints

1. Formats

Multiple formats can be used to import or export vocabulary. Except with some formats, the first column contains the term name. You can specify what you want to export and how additional columns should be imported.
Vocabulary structure should be imported first when multiple files are used. So choose options Fields and links, flat, structure, polyhierarchy, first level of parents or children before relations, descriptions, etc.

1. Alone terms

Terms are imported as simple terms. Additional columns are ignored. Example:

This option allows to import full term definitions and direct links to other terms.

Format is: term name, term id, vocabulary id, term description, weight, number of synonyms, number of first level parents, number of first level children, number of related terms, list of synonyms, list of first level parents ids, list of first level children ids, list of related terms ids, list of vocabulary ids of related terms.

Only term name should be defined. Other values can be empty. Ids are not internal term ids or vocabulary ids, but a unique identifiant. Ids can be a number or a name. In most case, you can use true name. In fact, term ids need to be specific only for duplicate term names in order to identify each item. So for duplicates, you can use term name with a serial number. Main term id is needed only when term name is a duplicate one.

Example with one synonym, two first level parents, no children, one relation with a term of another vocabulary:

With this source content, destination is determined by source. If third column is empty, a new vocabulary will be created. If it's a name or a number, a vocabulary will be created if it doesn't exist. This process is used for related terms too. If vocabulary of a related term is not defined, vocabulary of main term is used. Warning: It's not recommended to change the vocabulary of a term with links.

A simpler option, Full term definitions, allows to import only definitions.

3. Terms (flat vocabulary)

Use this option to import a lot of terms in order to create a flat vocabulary. All items in your file will be imported as terms. Example:

4. Hierarchical tree structure or one term by line structure

Use this option to create a tree structure of a vocabulary (geography, classification...). To import a hierarchy with multiple parents as a genealogical one, it's advised to use "Polyhierarchy", "First level children" or "First level parents" imports.

Your file can be written with two schemes and a mixed one.
First scheme: Full ancestors of a term
In the first scheme, you need to set all ancestors to each term. The second column will be imported as the name of a child term of the term defined by the first column. The third column will be imported as a child of the second column, and so on. Lines can have any order. Example:
Be careful: when a child is added or updated, line should contain all its ancestors. So a third line may be:
but not:
because in this second case, < Mammal > is imported as a first level term and not as a < Animal > term child as in previous line.
Second scheme: One term by line
In the "one term by line structure" scheme, you can import terms without duplicate all its ancestor if previous term has ancestors. It is very useful with a spreadsheet application. It allows to easy build a structure and to upload a less heavy file. So your hierarchy can be:
World
Asia
Japan
Tokyo
Korea
Seoul

So, first lines of your csv file can be:
< Paris > will be automatically added as a child of < France > and so on.
Mixed scheme

Partial lines are allowed, so a next line can be:

< Switzerland > will be added as a child of < Europe > and of course < Bern > as a child of < Switzerland >.

In same way, above lines can be simplified to:

Full lines, partial and one term lines can be mixed, but order is important two by two lines, except when there are only full lines. In this example, if fifth and sixth lines are shift, < Seoul > will become a child of < Japan >.

5. Polyhierarchical structure

Use this option to create a a polyhierarchical structure, as a genealogy.
Format is the same than tree structure: each term is the child of previous item: parent, child, sub-child... and so on.
There are four differences. First, the first item doesn't need to be a root. Second, duplicate terms are always merged, except when one is the direct parent of the other one, because it's forbidden in Drupal. So, if the vocabulary is monohierarchical and without non-direct duplicate terms, as in the previous geographical example, result is the same than with previous option. Third, lines can be partial too, but in some case of duplicates, result may differ. Last, polyhierarchy can be recursive.
For example, lines may be:

6. First level parents

This choice allows to create a vocabulary in which terms can have more than one parent, as in a genealogy (polyhierarchy).
The first item is imported as a term, the second and next as first level parents of first term. For example, lines may be:

7. First level children

This choice allows to create a vocabulary in which terms can have more than one parent, as in a genealogy (polyhierarchy).
The first item is imported as a term, the second and next as first level children of first term. For example, lines may be:

The three previous examples import the same vocabulary when existing items option is "update and merge", which is the recommended one.

8. Related terms

Warning: in Drupal 7, related terms have been removed and replaced by fields. So this option is available only with Drupal 6. To get same functionnality, you need to create a "relations" field.
Use this option to create links between terms, as "see also" in an encyclopedia. The second and next columns will be imported as related terms of the first column term. For example, a line may be:

So < Baobab > will be related to < Madagascar > and < Ghost >. An option allow you to create subrelations, here between < Madagascar > and < Ghost > (see below).

9. Full term definitions

This option allows to import full term definitions. Format is: name, weight, description, list of synonyms if any. Example:

A more complete option, Full term fields and links, allows to import not only definitions, but links to other terms too.

10. Term descriptions

The second column will be imported as the term description of the first column term. Example:

11. Term weights

The second column will be imported as weight of the term defined by first column. Example:

12. Synonyms terms

The second and next columns will be imported as synonyms terms of the first column term. Example:

13. Taxonomy manager

This format is used by Taxonomy manager to export vocabularies. Columns are: vocabulary id, term id, term name, term description, first level parent 1, ..., first level parent n. Example:

In this format, order of all lines is important: it's impossible to attach a parent to an item if this parent hasn't been imported in a previous line.
When a vocabulary is imported in an existing one, only option "ignore existing terms" can be used.

2. Import

Taxonomy CSV allows to import structure and properties of terms.

1. What to import (content of the source)?

Source can be configured with the first field set. See formats.

2. Where are terms to import?

You can import your terms from a file or with a text area. Simply check your choice. File can be a local file path or a url.

Advanced settings allows to set non standard delimiter and enclosure.

3. Where to import into (vocabulary destination)?

You can import your terms in a existing vocabulary or create a new one. You can import your terms too in a duplicate of an existing vocabulary.

When you want to import a new taxonomy into an existing one, it is recommended to process in three steps in order to allow a good import.

If you only want to create a new vocabulary, the first choice is sufficient, unless when you have multiple files for one vocabulary.

When source content is Full term definitions and links, destination is determined by source. If third column is an id, a new vocabulary will be created. If it's a name, a vocabulary will be created if it doesn't exist. If it's empty or zero, a vocabulary will be autocreated, duplicated or used depending on the destination option. This process is used for related terms too.

4. How to import your terms?

Destination can be configured with the next field set. You can specify what will become existing terms. Four choices are possible, or less matching your source content:

5. Big taxonomies import

To import big taxonomies (from 1000 or 10000 lines depending on the server) when access to time and memory settings of server are forbidden, it is recommended first to disable some other taxonomy related modules as "pathauto" before import. Settings aren't lost when you disable a module - and not uninstall it -. After import process, modules can be reactivated.
Second, you can use file import. Third, you can reduce log level. Fourth, you can use these tweaks.

Warning: with default Drupal "List terms" function, a memory error can occurs with big taxonomies. So use another manager as Taxonomy manager.

3. Export

Taxonomy CSV allows to export structures and properties of terms of one or all vocabularies.

Simply choose what you want to export (see formats) and how to export. Some formats may be unavailable.

4. Taxonomy csv import API

This module can be used as an API. You can use the full module as a dependance or use the light version taxonomy_csv.line.api.inc directly in your module. Import is run as this:

$result = taxonomy_csv_line_import(
  array("Europe", "France", "Paris"),
  array(
    'import_format' => 'tree_structure',
    'vocabulary_id' => 2,
    'existing_items' => 'update_replace',
));

Possible formats are explained in comments or above. Some may be unavailable.

Full version of API is available in the module. Light version is available in HEAD branch of cvs repository.

5. Advanced settings and hints

1. Delimiters and enclosures

2. Permissions

To import terms, user need one permission:

To export terms, user need one permission:

These permissions are often associated with these ones:

3. Other hints

Another Drupal module allows CSV import too, despite its name: taxonomy XML. Its approach is different: it uses one file compliant to thesauri standard ISO 2788, i.e. a three columns csv file: term, type of link (relation, description, synonym...), item, or, for specialists, subject, predicate, object. Additional fields are managed as the third one. For Drupal 4.7 and Drupal 5, taxonomy batch operations is available too. So choose the module best matching your needs.

For export, you can use Taxonomy XML too or one of backup modules. Taxonomy CSV is a more specialised tool which allows more precise tuning.