public function views_oai_pmh_xml_node::draw in Views OAI-PMH 7.2
Same name and namespace in other branches
- 6.2 plugins/includes/views_oai_pmh_xml_node.inc \views_oai_pmh_xml_node::draw()
Creates the XML for this node. If the object's $value property is an array, this method recursively calls the draw() method on each of the views_oai_pmh_xml_node objects in the $value array and returns the combined XML output.
Parameters
int $indent_level: The amount by which to indent this XML node in the output string. Recursive calls to draw() on child views_oai_pmh_xml_node objects increase the indent level by 1 each time.
Return value
string A string containing the generated XML code ready for output.
File
- plugins/
includes/ views_oai_pmh_xml_node.inc, line 175 - Definition of the views_oai_pmh_xml_node class.
Class
- views_oai_pmh_xml_node
- A class designed to represent an XML node, specially designed to help the Views OAI PMH module render OAI fields as XML elements.
Code
public function draw($indent_level = 0) {
// Create an indent string appropriate to the current indent level.
$indent = str_repeat(' ', $indent_level);
// Build up a string containing this node's attributes.
$attrs = array();
if (is_array($this->attributes)) {
foreach ($this->attributes as $key => $value) {
$attrs[] = $key . '="' . $value . '"';
}
}
$attrs = implode(' ', $attrs);
if ($attrs) {
$attrs = ' ' . $attrs;
}
// Construct the buffer string containing this node and all its descendants.
$buffer = '';
// Case 1: $this->value contains an array.
if (is_array($this->value)) {
// Increase the indent level for drawing our child objects.
$indent_level++;
// Find out the type of key used to index the $this->value array
reset($this->value);
$first_key = key($this->value);
// Case 1A: The contained array holds named XML objects. Draw this object, then draw its children.
if (!is_numeric($first_key)) {
$tag = $this
->process_tag_name($this->key);
$buffer .= $indent . '<' . $tag . $attrs . '>' . "\n";
foreach ($this->value as $child) {
$buffer .= $child
->draw($indent_level);
}
$buffer .= $indent . '</' . $tag . '>' . "\n";
}
else {
foreach ($this->value as $child) {
$buffer .= $child
->draw($indent_level);
}
}
}
elseif (is_a($this->value, 'views_oai_pmh_xml_node')) {
$tag = $this
->process_tag_name($this->key);
$buffer .= $indent . '<' . $tag . $attrs . '>' . "\n";
$buffer .= $this->value
->draw($indent_level);
$buffer .= $indent . '</' . $tag . '>' . "\n";
}
elseif ($this->value != '') {
$tag = $this
->process_tag_name($this->key);
$buffer .= $indent . '<' . $tag . $attrs . '>' . $this->value . '</' . $tag . '>' . "\n";
}
else {
$tag = $this
->process_tag_name($this->key);
$buffer .= $indent . '<' . $tag . $attrs . ' />' . "\n";
}
return $buffer;
}