Last updated April 23, 2012. Created by Sorin Sarca on April 22, 2012.
Log in to edit this page.

Feed Import is a module that allows you to import content into entities from various file types (like XML, HTML, CSV).
In this page we will find how to import taxonomy terms.

Our terms will be plants and we'll use an xml file from w3schools http://www.w3schools.com/xml/plant_catalog.xml.

Import code for feed below can be found here.

First, create a new vocabulary named Plants (admin/structure/taxonomy/add).
Add a new feed named Taxonomy Plants, for entity name select taxonomy_term and for url use
http://www.w3schools.com/xml/plant_catalog.xml

Feed Import Taxonomy Term

Click add button then go edit your new feed configuration. Open xml file and take a look at its structure to find xpaths.
You can see that the parent xpath will be //PLANT. We don't use an unique identifier because this is a one time import but if you don't want to have duplicate terms you can add the same xpath as the name have (see below the xpath for name).

Feed Import Taxonomy Plants XPATHs

Add field named name with xpath COMMON
You can also add field named description where you can save botanical name with xpath BOTANICAL

Feed Import Taxonomy Name

You have to specify in which vocabulary you want this term so add field named vid (which stands for vocabulary id). For this field use "Action when filtered result is empty" set to "Provide a filtered default value" and as a default value the vocabulary name, which is Plants.

Feed Import Vid Field

One step left to do: add a filter for vid field to get id from name. Click on Edit filters tab and add a new filter for vid field with name Get vocabulary id, function name ::getVidFromName and one param: [field]

Feed Import Vid filter

Save settings and you are ready to import the feed.
After import you should have about 36 taxonomy terms in Plants vocabulary.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

I'm trying to import taxonomy terms using a csv format -- I've set up the importer as above with a few exceptions:

1. my url is to a local csv file
2. processing function = csv
3. set column names (under processing function settings) to 1 --so column names are skipped.
4. parent XPATH = //row

otherwise it's the same (meaning i set the 'field' values as you have them): name is set identically and vid filter settings are the same (except I set the default name to the particular vocabulary on my site).

it says it 'processed' -- but no new terms show up in vocabulary.... do you have a simple 'import terms from csv' file I could see to ensure my settings are correct... or is there a way to figure out where the fail is occurring? thanks