function taxonomy_xml_xml_create in Taxonomy import/export via XML 6.2
Same name and namespace in other branches
- 5.2 xml_format.inc \taxonomy_xml_xml_create()
- 5 xml_format.inc \taxonomy_xml_xml_create()
- 6 xml_format.inc \taxonomy_xml_xml_create()
- 7 formats/xml_format.inc \taxonomy_xml_xml_create()
Return an XML representation of a taxonomy.
Parameters
$vid: Which vocabulary to generate the tree for.
$parent: The term ID under which to generate the tree. If 0, generate the tree for the entire vocabulary.
$depth: Internal use only.
$max_depth: The number of levels of the tree to return. Leave NULL to return all levels.
Return value
The text of an XML document.
File
- ./
xml_format.inc, line 47 - Include routines for the original XML parsing and taxonomy/term creation.
Code
function taxonomy_xml_xml_create($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
$output = "<?xml version=\"1.0\" standalone=\"no\"?>\n";
$output .= "<!DOCTYPE taxonomy SYSTEM \"taxonomy.dtd\">\n";
$tree = taxonomy_get_tree($vid, $parent, $depth, $max_depth);
if ($tree) {
$vocabulary = taxonomy_vocabulary_load($vid);
$output .= "<vocabulary>\n";
foreach ($vocabulary as $key => $value) {
if (is_array($value)) {
$output .= "<{$key}>" . check_plain(implode(',', $value)) . "</{$key}>";
}
else {
$output .= "<{$key}>" . check_plain($value) . "</{$key}>";
}
}
foreach ($tree as $term) {
$synonyms = taxonomy_get_synonyms($term->tid);
$output .= "<term>";
foreach ($term as $key => $value) {
if ($key == 'parents') {
foreach ($value as $parent) {
$output .= "<parent>" . check_plain($parent) . "</parent>";
}
}
else {
$output .= "<{$key}>" . check_plain($value) . "</{$key}>";
}
}
if ($synonyms) {
$output .= "<synonyms>";
$output .= implode("\n", $synonyms);
$output .= "</synonyms>";
}
$output .= "</term>";
}
$output .= "</vocabulary>\n";
}
return $output;
}