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
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).
Add field named name with xpath COMMON
You can also add field named description where you can save botanical name with xpath BOTANICAL
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.
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]
Save settings and you are ready to import the feed.
After import you should have about 36 taxonomy terms in Plants vocabulary.
Attachment | Size |
---|---|
feed-import-add-taxonomy-plants.png | 19.93 KB |
feed-import-plant-taxonomy-settings.png | 7.28 KB |
feed-import-field-name-common.png | 13.29 KB |
feed-import-vid-field.png | 11.35 KB |
feed-import-vid-filter.png | 9.2 KB |
feed-import-taxonomy-terms-plants.txt | 1.74 KB |
Comments
trying to get this to work using csv
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