function taxonomy_xml_add_terms_as_rdf in Taxonomy import/export via XML 6.2
Same name and namespace in other branches
- 5.2 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
- 5 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
- 6 rdf_format.inc \taxonomy_xml_add_terms_as_rdf()
Given a list of terms, append definitions of them to the passed DOM container
Following w3c, SUMO and Wordnet examples (tho not any explicit instructions, taxonomy terms are modelled as rdfs:Class objects structured using rdfs: subClassOf statements.
Sample from Wordnet:
<Class rdf:about="http://xmlns.com/wordnet/1.6/Cat"> <label>Cat [ 1 ]</label> <comment>feline mammal usually having thick soft fur and being unable to roar; domestic cats; wildcats</comment> <subClassOf> <Class rdf:about="http://xmlns.com/wordnet/1.6/Feline" /> </subClassOf> </Class>
I'm copying that syntax.
Parameters
$termlist a FLAT array of all terms, internally cross-referenced to: each other defining the tree stucture
2 calls to taxonomy_xml_add_terms_as_rdf()
- taxonomy_xml_rdf_create in ./
rdf_format.inc - Return an XML/RDF document representing this vocab
- taxonomy_xml_rdf_export_term in ./
rdf_format.inc - Return a term as RDF. Header and all
File
- ./
rdf_format.inc, line 1046 - Include routines for RDF parsing and taxonomy/term creation. @author dman http://coders.co.nz
Code
function taxonomy_xml_add_terms_as_rdf(&$domcontainer, $termlist, $vocabulary) {
if (!$termlist) {
return;
}
$dom = $domcontainer->ownerDocument;
$mapping = taxonomy_xml_get_mapping('taxonomy_term');
// Allow submission of a single term
if (!is_array($termlist)) {
$termlist = array(
$termlist,
);
}
foreach ($termlist as $term) {
module_invoke_all('taxonomy_term_load', $term);
$term->uri = taxonomy_xml_taxonomy_term_uri($term);
// List child terms, this will help if breaking the XML into lumps
$term->child = taxonomy_get_children($term->tid, $term->vid);
$termnode = taxonomy_xml_entity_to_rdf($term, 'taxonomy_term', $domcontainer);
// That has already added it to the document - required to prevent it adding dummy namespaces
$termnode
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:ID', $term->uri['id']);
// Add this because it helps visualizations
if (empty($term->parent)) {
$vocabulary_uri = taxonomy_xml_taxonomy_vocabulary_uri($term->vid);
$rel_node = $dom
->createelementns(TAXONOMY_XML_SKOS_NS, 'skos:topConceptOf');
$rel_node
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:resource', '#' . $vocabulary->uri['id']);
$termnode
->appendchild($rel_node);
}
if ($guid = taxonomy_xml_get_term_guid($term)) {
$termnode
->setattributens(TAXONOMY_XML_RDF_NS, 'rdf:about', $guid);
}
// Additional module support
// eg taxonomy_image, geotaxonomy, path
//
$hook = 'taxonomy_xml_rdf_export_term';
// Can't use module_invoke as we need pass-by-ref
foreach (module_implements($hook) as $module) {
$function = $module . '_' . $hook;
$function($termnode, $term);
}
# dpm(array('adding term to rdf' => $term));
#$termnode->appendchild($dom->createcomment(print_r($term, 1)));
// workaround for large vocabs - extend runtime indefinately
set_time_limit(10);
}
// Done all terms in list
}