You are here

function taxonomy_xml_tcs_create in Taxonomy import/export via XML 6

Same name and namespace in other branches
  1. 6.2 tcs_format.inc \taxonomy_xml_tcs_create()
  2. 7 formats/tcs_format.inc \taxonomy_xml_tcs_create()

Return an XML/TCS document representing this vocab

Uses PHP DOM to create DOM document and nodes.

We use namespaces carefully here, although it may create wordy output if the DOM is not optimizing the declarations for us. Still, best to be explicit, it would seem.

The URI used to refer to other resources is based on the source document location, eg http://this.server/taxonomy_xml/{vid}/rdf#{tid}

Preamble should look something like:

<?xml version="1.0" encoding="UTF-8"?> <DataSet xmlns: xsi="http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation="http://www.tdwg.org/schemas/tcs/1.01 http: //tdwg.napier.ac.uk/TCS_1.01/v101.xsd" xmlns=" http://www.tdwg.org/schemas/tcs/1.01">

1 call to taxonomy_xml_tcs_create()
taxonomy_xml_file in ./taxonomy_xml.module
taxonomy_xml_file

File

./tcs_format.inc, line 292
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_tcs_create($vid, $parent = 0, $depth = -1, $max_depth = NULL) {
  $vocabulary = taxonomy_vocabulary_load($vid);
  $domcontainer = taxonomy_xml_tcs_document();
  $dom = $domcontainer->ownerDocument;

  // and more details?
  // Now start adding terms.
  // They are listed as siblings, not children of the ontology
  $tree = module_invoke('taxonomy', 'get_tree', $vid, $parent, $depth, $max_depth);
  taxonomy_xml_add_terms_as_tcs($domcontainer, $tree);
  $result = $dom
    ->savexml();

  // Minor layout tweak for readability
  $result = preg_replace('|(<[^<]*/[^>]*>)|', "\$1\n", $result);
  $result = preg_replace('|><|', ">\n<", $result);

  #dpm($result);
  return $result;
}