Index: wordpress-importer.php
===================================================================
--- wordpress-importer.php	(revision 298755)
+++ wordpress-importer.php	(working copy)
@@ -463,15 +463,8 @@
 		$post_content = str_replace('<br>', '<br />', $post_content);
 		$post_content = str_replace('<hr>', '<hr />', $post_content);
 
-		preg_match_all('|<category domain="tag">(.*?)</category>|is', $post, $tags);
-		$tags = $tags[1];
+		preg_match_all('|<category\s*(?:\bdomain="(.*?)"\s*)?(?:\bnicename="(.*?)")?>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?</category>|', $post, $terms, PREG_SET_ORDER);
 
-		$tag_index = 0;
-		foreach ($tags as $tag) {
-			$tags[$tag_index] = $wpdb->escape( html_entity_decode( str_replace(array( '<![CDATA[', ']]>' ), '', $tag ) ) );
-			$tag_index++;
-		}
-
 		preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
 		$categories = $categories[1];
 
@@ -556,26 +549,30 @@
 			}
 
 			// Add terms.
-			if (count($tags) > 0) {
-				$post_tags = array();
-				foreach ($tags as $tag) {
-					if ( '' == $tag )
+			if (count($terms) > 0) {
+				$post_terms = array();
+				foreach ($terms as $term) {
+					if ( '' == $term[1] || 'category' == $term[1])
 						continue;
-					$slug = sanitize_term_field('slug', $tag, 0, 'post_tag', 'db');
-					$tag_obj = get_term_by('slug', $slug, 'post_tag');
-					$tag_id = 0;
-					if ( ! empty($tag_obj) )
-						$tag_id = $tag_obj->term_id;
-					if ( $tag_id == 0 ) {
-						$tag = $wpdb->escape($tag);
-						$tag_id = wp_insert_term($tag, 'post_tag');
-						if ( is_wp_error($tag_id) )
+					$slug = $term[2];
+					echo $slug;
+					$domain = $term[1];
+					if ($domain == 'tag') {
+						$domain = 'post_tag';
+					}
+					$term = $wpdb->escape($term[3]);
+					$term_id = term_exists( $term, $domain );
+					if ( $term_id || $term_id != 0) {
+						echo $term_id;
+					} else {
+						$term_id = wp_insert_term($term, $domain);
+						echo $term_id;
+						if ( is_wp_error($term_id) )
 							continue;
-						$tag_id = $tag_id['term_id'];
+						$term_id = $term_id['term_id'];
 					}
-					$post_tags[] = intval($tag_id);
+					wp_set_post_terms($post_id, $term, $domain,true);
 				}
-				wp_set_post_tags($post_id, $post_tags);
 			}
 		}
 
