How to add Drupal taxonomy terms in bulk
Drupal taxonomy module is a useful and powerful module that allows you to categorize your web content. No matter you are setting your personal blog or a large community website, you probably will need this feature at some time. Adding vocabularies and terms in Drupal is not difficult. However, if you have a large amount of terms, you'll find this process quite time consuming and tedious. In this article, I will show you very briefly how to add terms in bulk.
There are three contributed modules in Drupal at your disposal that allow you to add multiple terms in a single run.
As shown in the screenshot below, Taxonomy Batch Operations provides a text area that allows you to enter one term a line. You can either manually enter them if you only need a few terms, or copy&paste if you have a long list in a text file or spreadsheet. Simple interface, but powerful enough to meet most your needs.

With this module, it's also possible to delete multiple terms on one page as shown below:

Since the current version is still buggy (see http://drupal.org/node/118983) and the patches are not committed yet, I made the tarball myself with the patch to save some trivial work for others (taxonomy_batch_operations.tar_.gz).
Taxonomy Manager provides many interesting features, which could be very useful for managing taxonomy terms. For adding new terms, however, it only allows maximum six terms each time. Apparently a lot of manual work is still needed if you have hundreds thousands of terms.

Finally with taxonomy_xml you can import and export vocabularies and taxonomy terms via XML. Obviously you need to have an XML file first in order to import the terms. To make my life and hopefully your life easier, I wrote a simple perl script to convert a text file with a list of terms into a XML file readable by taxonomy_xml module. To use this script, just run
perl taxonomy_list2xml.pl input.txt output.xml
A sample list of world languages generated by this script is attached below, and a live demo can be seen here (note: IE seems to have problems opening this file).
| Attachment | Size |
|---|---|
| taxonomy_batch_operations.tar_.gz | 10.84 KB |
| taxonomy_list2xml.pl.txt | 1.08 KB |
| taxonomy_languages.xml | 24.3 KB |
- xjs's blog
- 17466 reads
SpeakingX












Comments
I love this...
I love the concept of this simple program you shared to us...thanks a lot. writing services
To my mind
Thanks for pointing this out. At one of forums I was recommended to use torrent search engines and this is really very convenient. try yourself!
Simple interface, but
Simple interface, but powerful enough to meet most needs.
What about group select?
What about a module that allows you to check multiple content items and apply taxonomy to all? I'm sure it's there and I just haven't seen it.
Pearl Script
I'm curious as to how to use the taxonomy_list2xml.pl.txt file ... I have installed Active Perl on my local pc and am trying to figure this out ... however a step by step would be very helpful.
I dont know how to run the script. I looked through it as well and could not find any area where you would add the path to the text file which needs to be converted. Im sure its something stupid and simple I am missing.
I figured trying to run this locally would be best as my text file is over 200 megs thats why I have installed Active Perl ... My file contains all regions countries states/provinces and cities etc. If we could get this cleaned im sure there are plenty of people who could use it in their drupal sites.
below are some explanations that might be useful
hello
very cool realy thanks....evden eve nakliyat
Importing hierarchy in taxonomy through xml.
I have used your script and found it really helpful. I have tried remodelling the script so that it can handle hierarchy, but failed to do so.
Do you have a solution to this problem. Kindly help.
One more problem is that in drupal taxonomy_xml import export module doesnt supports duplicacy,but in my project i need duplicate elements in my hierarchy.
A quick response from you will be very much appreciated.
Thanks!!
Sorry for the late response.
Sorry for the late response. Just saw your comments. Unfortunately I have no experiences with hierarchy. Hopefully you've found solutions by now.
Ahh
Your tips were very helpful to understand the pearl script. The hierarchy is a bit of a problem as you guessed it im attempting to bring in data with several hierarchies. Thanks anyhow ... maybe there is someone who has it done already... I'll keep hunting.
Other XML terms
Howdy,
thanks for sharing, this actually saves quite a lot of time!
I'm working on some other sets of taxonomy terms ATM, mainly about countries and regions of Italy. They can be found here in case someone else needs.
All the best,
-marco
Let me know if there're any problems with the script
The code was written very quickly. The only test I've done is importing the language list. So there might be bugs
Feedback is always welcome. Thanks!
Post new comment