You are here

public static function RestWSFormatXML::xmlToArray in RESTful Web Services 7

Same name and namespace in other branches
  1. 7.2 restws.formats.inc \RestWSFormatXML::xmlToArray()

Turns the xml structure into an array of values.

1 call to RestWSFormatXML::xmlToArray()
RestWSFormatXML::unserialize in ./restws.formats.inc

File

./restws.formats.inc, line 253
RESTful web services module formats.

Class

RestWSFormatXML
A formatter for XML.

Code

public static function xmlToArray(SimpleXMLElement $xml) {
  $children = $xml
    ->children();
  foreach ($xml
    ->children() as $name => $element) {
    $result[$name] = self::xmlToArray($element);
  }
  if (!isset($result)) {
    $result = ($string = (string) $xml) ? $string : NULL;
  }
  return $result;
}