How to import nested categories from XML file?

We're importing an eXtended RSS file generated by WordPress thru the native Importer:

Tools: Import in the WordPress admin panel

Importing parent posts is straightforward, by defining the respective parent id:

wp:post_parent1/wp:post_parent

However, during the export the hierarchy of categories, subcategories and so on gets lost, and we're trying to set the according parent categories inside xml file. We've tried the following without any success:

category domain=docs_category nicename=category-1![CDATA[Category]]/category

And for another post:

category domain=docs_category nicename=subcategory-1 parent=category-1![CDATA[Subcategory]]/category

We cannot find any explicit documentation regarding build of such Wordpress RSS file.

Could someone please point out a link to the documentation on Wordpress?

Moreover, the closest example we've found was on GitHub:

wp:category
        wp:term_id2/wp:term_id
        wp:category_nicename![CDATA[test-category-1]]/wp:category_nicename
        wp:category_parent![CDATA[]]/wp:category_parent
        wp:cat_name![CDATA[Test Category 1]]/wp:cat_name
/wp:category
wp:category
        wp:term_id3/wp:term_id
        wp:category_nicename![CDATA[test-subcategory-1]]/wp:category_nicename
        wp:category_parent![CDATA[test-category-1]]/wp:category_parent
        wp:cat_name![CDATA[Test Subcategory 1]]/wp:cat_name
/wp:category

We're not working with the taxonomy domain=category, but wp:category_parent sets us on the right path.

The question is:

How to set the correct parent category for each channel item, i.e. each unique post individually?

Thanks in advance for any help on this kind of urgent matter!

Topic xml categories import posts Wordpress

Category Web


The following code snippet did the trick:

<wp:term>
    <wp:term_id><![CDATA[1]]></wp:term_id>
    <wp:term_taxonomy><![CDATA[category]]></wp:term_taxonomy>
    <wp:term_slug><![CDATA[test-category-1]]></wp:term_slug>
    <wp:term_parent><![CDATA[]]></wp:term_parent>
    <wp:term_name><![CDATA[Test Category 1]]></wp:term_name>
</wp:term>
<wp:term>
    <wp:term_id><![CDATA[2]]></wp:term_id>
    <wp:term_taxonomy><![CDATA[category]]></wp:term_taxonomy>
    <wp:term_slug><![CDATA[sub-category-1]]></wp:term_slug>
    <wp:term_parent><![CDATA[test-category-1]]></wp:term_parent>
    <wp:term_name><![CDATA[Sub Category 1]]></wp:term_name>
</wp:term>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.