You are here

public static function FrxData::arrayToXml in Forena Reports 7.4

4 calls to FrxData::arrayToXml()
FrxContextBase::asXML in contexts/FrxContextBase.inc
Return the properteis of the element.
FrxData::getValue in ./FrxData.inc
Get the value from the data. This is used by token_replace method to extract the data based on the path provided.
FrxRenderer::renderDomNode in renderers/FrxRenderer.inc
Recursive report renderer Walks the nodes rendering the report.
FrxXML::render in renderers/FrxXML.inc
Default Render action, which simply does normal forena rendering. You can use renderDomNode at any time to generate the default forena rendering methods.

File

./FrxData.inc, line 111

Class

FrxData

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';
      FrxData::arrayToXml($v, $node);
    }
    else {
      $node = $xml
        ->addChild($tag, htmlspecialchars($v));
      $node['key'] = $k;
    }
    $tag = preg_replace('/[^a-zA-Z0-9]/', '_', (string) $k);
  }
  return $xml;
}