category_tree::xml::import (public)

 category_tree::xml::import [ -site_wide ] xml

Defined in packages/categories/tcl/category-xml-procs.tcl

Imports a category tree from an XML representation.

Switches:
-site_wide (optional, boolean)
Parameters:
xml (required)
A string containing the source XML to import from
Returns:
The category tree identifier
Author:
Tom Ayles <tom@beatniq.net>

Partial Call Graph (max 5 caller/called nodes):
%3 test_category_tree_import category_tree_import (test categories) category_tree::xml::import category_tree::xml::import test_category_tree_import->category_tree::xml::import category_tree::add category_tree::add (public) category_tree::xml::import->category_tree::add category_tree::update category_tree::update (public) category_tree::xml::import->category_tree::update category_tree::xml::add_category category_tree::xml::add_category (private) category_tree::xml::import->category_tree::xml::add_category db_transaction db_transaction (public) category_tree::xml::import->db_transaction dom dom category_tree::xml::import->dom category_tree::xml::import_from_file category_tree::xml::import_from_file (public) category_tree::xml::import_from_file->category_tree::xml::import

Testcases:
category_tree_import
Source code:
    # recode site_wide_p to DB-style boolean
    if {$site_wide_p} { set site_wide_p t } elseset site_wide_p f }

    set doc [dom parse -- $xml]
    if {[catch {set root [$doc documentElement]} err]} {
        error "Error parsing XML: $err"
    }

    set tree_id 0

    db_transaction {
        foreach translation [$root selectNodes {translation}] {
            if {[catch {set locale [$translation getAttribute locale]}]} {
                error "Required attribute 'locale' not found"
            }
            if {[catch {set name [[$translation selectNodes {name}] text]}]} {
                error "Required element 'name' not found"
            }
            if {[catch {set description [[$translation selectNodes {description}] text]}]} {
                set description {}
            }
            if {$tree_id} {
                # tree initialized, add translation
                category_tree::update  -tree_id $tree_id  -name $name  -description $description  -locale $locale
            } else {
                # initialize tree
                set tree_id [category_tree::add  -site_wide_p $site_wide_p  -name $name  -description $description  -locale $locale]
            }
        }

        foreach category [$root selectNodes {category}] {
            add_category -tree_id $tree_id -parent_id {} $category
        }
    }
    
    $doc delete

    return $tree_id
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: