_nestoria_simplexml2array

Definition

_nestoria_simplexml2array($xml)
nestoria/nestoria.module, line 132

Code

function _nestoria_simplexml2array($xml) {
  if (get_class($xml) == 'SimpleXMLElement') {
    $attributes = $xml->attributes();
    foreach($attributes as $k=>$v) {
      if ($v) $a[$k] = (string) $v;
    }
    $x = $xml;
    $xml = get_object_vars($xml);
  }
  if (is_array($xml)) {
    if (count($xml) == 0) return (string) $x; // for CDATA
      foreach($xml as $key=>$value) {
        $r[$key] = _nestoria_simplexml2array($value);
      }
 #   if (isset($a)) $r['@'] = $a;    // Attributes
     return $r;
  }
   return (string) $xml;
}