You are here

protected function HttpClientXMLFormatter::xml_recurse in Http Client 7.2

Same name and namespace in other branches
  1. 6.2 includes/HttpClientXMLFormatter.inc \HttpClientXMLFormatter::xml_recurse()

Directly stolen from http_server by Hugo Wetterberg

1 call to HttpClientXMLFormatter::xml_recurse()
HttpClientXMLFormatter::serialize in includes/formatter/HttpClientXMLFormatter.inc
Serializes arbitrary data to the implemented format. Directly stolen from http_server by Hugo Wetterberg

File

includes/formatter/HttpClientXMLFormatter.inc, line 116

Class

HttpClientXMLFormatter
Class for handling xml-responses. Returns a SimpleXML object

Code

protected function xml_recurse(&$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 {
        $assoc = TRUE;
        $key = $this
          ->sanitizeNodeName($key);
      }
      $element = $doc
        ->createElement($key);
      $parent
        ->appendChild($element);
      $this
        ->xml_recurse($doc, $element, $value);
    }
    if (!$assoc) {
      $parent
        ->setAttribute('is_array', 'true');
    }
  }
  else {
    if ($data !== NULL) {
      $parent
        ->appendChild($doc
        ->createTextNode($data));
    }
  }
}