You are here

public static function DataContext::arrayToXml in Forena Reports 7.5

Same name and namespace in other branches
  1. 8 src/Context/DataContext.php \Drupal\forena\Context\DataContext::arrayToXml()
2 calls to DataContext::arrayToXml()
DataContext::getValue in src/Context/DataContext.php
Get the value from the data. This is used by token_replace method to extract the data based on the path provided.
FrxXML::render in src/Renderer/FrxXML.php
Default Render action, which simply does normal forena rendering. You can use renderDomNode at any time to generate the default forena rendering methods.

File

src/Context/DataContext.php, line 115
DataContext.php The FrxData class holds all of the data contexts during the report rendering process. The general idea is that during the report render, data objects are pushed on the stack with the id's of the block or foreach objects that…

Class

DataContext

Namespace

Drupal\forena\Context

Code

public static function arrayToXml($a, &$xml = NULL) {
  if (!$xml) {
    $xml = new SimpleXMLElement('<root/>');
  }
  $tag = '';
  foreach ($a as $k => $v) {
    if (preg_match('/^[0-9\\-\\.]/', $k)) {
      if (!$tag) {
        $tag = "element";
      }
    }
    else {
      $tag = $k;
    }
    if (is_array($v) || is_object($v)) {
      $node = $xml
        ->addChild($tag, '');
      if ($tag != $k) {
        $node['key'] = $k;
      }
      $node['type'] = is_object($v) ? 'object' : 'array';
      \Drupal\forena\Context\DataContext::arrayToXml($v, $node);
    }
    else {
      $node = $xml
        ->addChild($tag, htmlspecialchars($v));
      $node['key'] = $k;
    }
    $tag = preg_replace('/[^a-zA-Z0-9]/', '_', (string) $k);
  }
  return $xml;
}