You are here

public function views_oai_pmh_xml_node::set_attributes_at in Views OAI-PMH 7.2

Same name and namespace in other branches
  1. 6.2 plugins/includes/views_oai_pmh_xml_node.inc \views_oai_pmh_xml_node::set_attributes_at()

Allows you to add attributes to an existing XML node, so you are not forced to add the attributes on creation.

Note: Only assigns attributes if the $attributes array is non-empty. This is so elements with existing sets of attributes don't have them overwritten by accident.

Parameters

array $node_address: An array of XML node names indicating the address of the node in the XML node tree. For example, passing array('a', 'b', 'c') as the parameter would create an XML node called 'c' and position it in a structure at: <a><b><c /></b></a>.

array $attributes : (optional) An array of key/value pair attributes of the new XML node.

File

plugins/includes/views_oai_pmh_xml_node.inc, line 141
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 set_attributes_at($node_address, $attributes) {
  if (!empty($attributes)) {
    $node =& $this;
    for ($i = 0; $i < count($node_address); $i++) {
      $node = $node
        ->get_node($node_address[$i]);
    }
    $node->attributes = $attributes;

    // See if this node contains multiple values.
    if (is_array($node->value)) {

      // Find out the type of key used to index the $this->value array
      reset($node->value);
      $first_key = key($node->value);
      if (is_numeric($first_key)) {
        foreach ($node->value as $child) {
          $child->attributes = $attributes;
        }
      }
    }
  }
}