You are here

public static function DataContext::arrayToXml in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 src/Context/DataContext.php \Drupal\forena\Context\DataContext::arrayToXml()
4 calls to DataContext::arrayToXml()
ContextBase::asXML in src/FrxPlugin/Context/ContextBase.php
Return the properteis of the element.
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/FrxPlugin/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.
RendererBase::renderDomNode in src/FrxPlugin/Renderer/RendererBase.php
Recursive report renderer Walks the nodes rendering the report.

File

src/Context/DataContext.php, line 89
Implements \Drupal\forena\Context\DataContext

Class

DataContext
The DataContext 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 invoke them.

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';
      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;
}