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 LibreOffice Calc or another spreadsheet application to export your data into a CSV file.
Specific import or export formats can be added simply by a plug-in mecanism (or ask author!).
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.
Terms are imported as simple terms. Additional columns are ignored. Example:
Diamond
Gold
Wood
Terms are imported with a csv scheme provided by the user.
The csv scheme should contain each column header of the csv input. The column header is the name (not the label) of the field where to import items into. It can be a default header (name, description, weight) or a custom field.
For example, you want to import a list of car makers, and you would like each car maker to have custom fields indicating nationality and date of origine(origine of example, fictional):
[Taxonomy Term] - [Custom Field] - [Custom Field]
Car Maker - Country - Year Started
-------------------------------------------------
Ford - US - 1900
Renault - France - 1901
Toyota - Japan - 1902
Nissan - Japan - 1903
Daimler Benz - Germany - 1904
So, with 'Custom fields' format, you can set your format:
name, field_country, field_year_started
or more generically:
name, field_mycustomfield_1_machinename, field_mycustomfield_2_machinename...
Custom fields are automatically created if they don't exist and then attached to the vocabulary.
Currently, custom fields can be 'text', reference to another term ('taxonomy_term_reference') and even 'file'.
The default type of field is 'text'. If you want to use another one, you have to set it with '|' symbol in the vocabulary section of the form, except if the field exists already.
For exemple, you want to import these items (origine of example):
default name 1, tax gtin name 1, description 1, /home/robertom/file1.pdf, status 1
default name 2, tax gtin name 2, description 2, /home/robertom/file2.pdf, status 2
default name 3, tax gtin name 3, description 3, /home/robertom/file3.pdf, status 3
Your custom format will be:
name, field_internal_name, description, field_file, field_status
Your custom fields will be:
field_file|file
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.
Examples:
foo, , , "Description of foo", 10, 1, 1, 2, 2, Synonym of foo, bar parent 1, bar child 1, bar child 2, bar related 1, bar related 2, , vocabulary of related 2
France, , Places, "A great country", 1, 1, 1, 3, 3, French Republic, Europe, Paris, Lyon, Vichy, USA, Japan, China
Japan, , Places, "An old country", 1, 1, 1, 2, 2, Land of the Rising Sun, Asia, Tokyo, Kyoto, China, France
China, , Places, "A big country", 2, 1, 1, 1, 2, Middle Kingdom, Asia, Beijing, Japan, France
Asia, , Places, "A large continent", 1, 0, 0, 2, 0, Japan, China
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 format, Full term definitions
, allows to import only definitions.
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:
Clothes, Trees, Houses
Paris, Drupal
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.Animal, Mammal, Whale
Animal, Mammal, Monkey
Animal, Mammal, Human
Mammal, Human
Mammal
> is imported as a first level term and not as a < Animal
> term child as in previous line.
World
Asia
Japan
Tokyo
Korea
Seoul
World
,Asia
,,Japan
,,,Tokyo
,,Korea
,,,Seoul
,Europe
,,France
,,,Paris
,,Italia,Abruzzo,Chieti,Chieti
,,,,,Civitaluparella
Paris
> will be automatically added as a child of < France
> and so on.
Partial lines are allowed, so a next line can be:
,,Switzerland,Bern
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:
World, Asia, Japan, Tokyo
,, Korea, Seoul
World, Europe, France, Paris
Seoul
> will become a child of < Japan
>.
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:
Grand-Mother, Mother, Daughter
Grand-Father, Mother, Son
Grand-Mother 2, Father, Daughter
Grand-Father 2, Father, Son
, , Son 2
, Uncle
Grand-Mother 2, Uncle
Father, Son 3
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:
Daughter, Mother, Father
Son, Mother, Father
Son 2, Father
Son 3, Father
Mother, Grand-Mother, Grand-Father
Father, Grand-Mother 2, Grand-Father 2
Uncle, Grand-Mother 2, Grand-Father 2
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:
Mother, Daughter, Son
Father, Daughter, Son, Son 2, Son 3
Grand-Mother, Mother
Grand-Father, Mother
Grand-Mother 2, Father, Uncle
Grand-Father 2, Father, Uncle
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 feature, 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:
Baobab, Madagascar, Ghost
Baobab
> will be related to < Madagascar
> and < Ghost
>. An option allow you to create subrelations, here between < Madagascar
> and < Ghost
> (see below).
The second and next columns will be imported as synonyms terms of the first column term. Example:
"United Kingdom", "Great Britain", "England"
This option allows to import full term definitions. Format is: name, weight, description, list of synonyms if any. Example:
Street, 1, "A urban way", Avenue, Road
Full term fields and links
, allows to import not only definitions, but links to other terms too.
The second column will be imported as the term description of the first column term. Example:
"Baobab","An African tree"
The second column will be imported as weight of the term defined by first column. Example:
Baobab, 3
This format is used by Taxonomy manager to export vocabularies. Columns are: vocabulary id, term id, term name, term description, first level parent id 1, ..., first level parent id n. Example:
, 1, "Île-de-France", "Main region"
, 2, "Paris", "Capital of France", 1
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.
Import and export geotaxonomy terms.
Format
name, latitude, longitude, parent, top, right, bottom, left boundaries
Exemple
"Paris", 48.833, 2.333, "Île-de-France"
"Île-de-France", 47, 2, "France"
Only name, latitude and longitude are needed. To set a parent is recommended to get a hierarchical structure.
Ids may be numbers or not, for example the name itself, but they need to be unique to avoid duplicate terms. Only duplicate names need to have an id.
Taxonomy CSV allows to import structure and properties of terms.
Source can be configured with the first field set. See formats.
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.
Import need to be utf-8 formatted, without byte order mark in preference.
This group of settings allows to set non standard delimiter and enclosure and specific locales, such as "fr_FR.utf8".
,
" by default, semicolon ";
" or tabulation) between terms can be chosen in Advanced settings in the second fieldset. You can choose a custom delimiter too. Delimiter is a one character string. Example with delimiter < ¤
>:term 1¤This field has commas, a semicolon (;), a quotation mark (") and a tabulation, but it will be correctly imported.
"
), specialy if they contain non-ASCII letters or if imported items, in particular descriptions, contain the chosen delimiter. Example:"term 1","This field has a comma, but it will be correctly imported."
"
) are automatically managed.
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.
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:
Update current terms when name matches with imported ones and merge existing descriptions, parents, synonyms and related terms with new ones. Duplicates are removed. This choice is recommended if you want to keep a vocabulary and if you have descriptions, parents, synonyms and related terms you don't want to lose.
Update current terms if name matches, but remove existing descriptions, parents, synonyms and related terms. Choose this option if you are want to create a clean new vocabulary without losing existing terms.
Be careful: if there is no description, parent, synonym or related term, i.e. the line contains only a term in the first column, this removes the existing.
Let current terms as they are and create a new term for the first column term.
Warning: This can create duplicate terms. It is recommended to use this option only if you are sure that imported taxonomy contains only new terms or if your vocabulary allows multiple parents.
Create a new term for each term on the line.
This group of options allows to choose informations displayed at end of process.
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.
Next, you can use these tweaks (in groups of options).
Stats, terms and notices or warnings displayed at the end of process are memory consomming. So, you can reduce or disable them.
As to calculate vocabulary hierarchy is memory intensive, this option allows to set hierarchy manually without verify it.
If you are sure that vocabulary to import is well formatted (utf8, order of items...), you can disable checks. This option increases import speed by 5%.
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.
This module can be used as an API. You can use the full module as a dependance or directly in your module. Import is run as this:
$csv_lines = '"Europe", "France", "Paris"';
$csv_lines .= "\n". ',, "Lyon"';
$csv_lines .= "\n". ',"United Kingdom", "London"';
$csv_lines .= "\n". ',"Portugal", "Lisbonne"';
$result = taxonomy_csv_import(
array(
'text' => $csv_lines,
'import_format' => 'tree_structure',
'existing_items' => 'update_replace',
));
Or as this (line level import):
$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.
More info can be found in TECHINFO.txt.
To import terms, user needs general taxonomy permissions (Drupal 6) or taxonomy permissions (Drupal 7). These permissions are often associated with access rights for administration pages.
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.