You are here

private function ServicesXMLFormatter::xml_recursive in Services 7.3

1 call to ServicesXMLFormatter::xml_recursive()
ServicesXMLFormatter::render in servers/rest_server/includes/ServicesFormatter.inc
Render data to the string.

File

servers/rest_server/includes/ServicesFormatter.inc, line 57

Class

ServicesXMLFormatter

Code

private function xml_recursive(&$doc, &$parent, $data) {
  if (is_object($data)) {
    $data = get_object_vars($data);
  }
  if (is_array($data)) {
    $assoc = FALSE || empty($data);
    foreach ($data as $key => $value) {
      if (is_numeric($key)) {
        $key = 'item';
      }
      else {
        if (empty($key)) {
          continue;
        }
        else {
          $assoc = TRUE;
          $key = preg_replace('/[^A-Za-z0-9_]/', '_', $key);
          $key = preg_replace('/^([0-9]+)/', '_$1', $key);
        }
      }
      $element = $doc
        ->createElement($key);
      $parent
        ->appendChild($element);
      $this
        ->xml_recursive($doc, $element, $value);
    }
    if (!$assoc) {
      $parent
        ->setAttribute('is_array', 'true');
    }
  }
  elseif ($data !== NULL) {
    $parent
      ->appendChild($doc
      ->createTextNode($data));
  }
}