function taxonomy_xml_add_terms_as_tcs in Taxonomy import/export via XML 6
Same name and namespace in other branches
- 6.2 tcs_format.inc \taxonomy_xml_add_terms_as_tcs()
- 7 formats/tcs_format.inc \taxonomy_xml_add_terms_as_tcs()
Given a list of terms, append definitions of them to the passed DOM container
Parameters
$termlist a FLAT array of all Drupal terms, internally cross-: referenced to each other defining the tree stucture
1 call to taxonomy_xml_add_terms_as_tcs()
- taxonomy_xml_tcs_create in ./
tcs_format.inc - Return an XML/TCS document representing this vocab
File
- ./
tcs_format.inc, line 355 - Include routines for the Taxon Concepts Schema as used by "the Encyclopedia of Life" original XML parsing and taxonomy/term creation. and others.
Code
function taxonomy_xml_add_terms_as_tcs(&$domcontainer, $termlist) {
if (!$termlist) {
return;
}
$dom = $domcontainer->ownerDocument;
$termscontainer = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'TaxonConcepts');
$domcontainer
->appendchild($termscontainer);
foreach ($termlist as $term) {
$termnode = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'TaxonConcept');
$termnode
->setattributens(TAXONOMY_XML_TCS_NS, 'id', 'term-' . $term->tid);
$termscontainer
->appendchild($termnode);
$propername = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'Name', $term->name);
$propername
->setattributens(TAXONOMY_XML_TCS_NS, 'scientific', 'true');
$propername
->setattributens(TAXONOMY_XML_TCS_NS, 'ref', '?');
$termnode
->appendchild($propername);
/*
foreach ((array) taxonomy_get_related($term->tid) as $relatedid => $relatedterm) {
$related_node = $dom->createelementns(TAXONOMY_XML_TCS_NS, 'rdfs:seeAlso', htmlentities($relatedterm->name) );
$related_node->setattributens(TAXONOMY_XML_TCS_NS, 'rdf:resource', '#term-'. $relatedid );
$termnode->appendchild($related_node);
}
*/
$synonyms = taxonomy_get_synonyms($term->tid);
foreach ((array) $synonyms as $synonym) {
$synonymname = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'Name', xmlentities($synonym));
$synonymname
->setattributens(TAXONOMY_XML_TCS_NS, 'scientific', 'false');
$termnode
->appendchild($synonymname);
}
$termrelations = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'TaxonRelationships');
$termnode
->appendchild($termrelations);
// Start adding relations
foreach ((array) $term->parents as $relatedid) {
$relatedlist = array();
if ($relatedid) {
$relatedlist[$relatedid] = $related = taxonomy_get_term($relatedid);
$relation_node = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'TaxonRelationship');
$relation_node
->setattributens(TAXONOMY_XML_TCS_NS, 'type', 'is child taxon of');
$termrelations
->appendchild($relation_node);
$relation_reference = $dom
->createelementns(TAXONOMY_XML_TCS_NS, 'ToTaxonConcept', xmlentities($related->name));
$relation_reference
->setattributens(TAXONOMY_XML_TCS_NS, 'ref', $related->tid);
$relation_node
->appendchild($relation_reference);
}
}
# $termnode->appendchild($dom->createcomment(print_r($term, 1)));
// workaround for large vocabs - extend runtime indefinately
set_time_limit(10);
}
// Done all terms in list
}