Converts SimpleXMLElement to an array
192940
static function simpleXmlToArray(SimpleXMLElement &$source)
  {
    $res = array();
    $children = false;
    foreach ($source as $key => $value) {
        CPS_Response::simpleXmlToArrayHelper($res, $key, $value, $children);
    }
    if ($source) {
      foreach ($source->children('www.clusterpoint.com') as $key => $value) {
        $newkey = 'cps:' . $key;
        CPS_Response::simpleXmlToArrayHelper($res, $newkey, $value, $children);
      }
    }
    if (!$children)
      return (string)$source;
    return $res;
  }
977802
protected function toArray()
    {
        $arr = [];
        $arr[Resources::XTAG_NAMESPACE] = [
            Resources::WA_XML_NAMESPACE => null,
        ];

        Utilities::addIfNotEmpty(Resources::XTAG_LABEL, $this->_label, $arr);
        Utilities::addIfNotEmpty(
            Resources::XTAG_DESCRIPTION,
            $this->_description,
            $arr
        );
        Utilities::addIfNotEmpty(
            Resources::XTAG_LOCATION,
            $this->_location,
            $arr
        );

        return $arr;
    }
518148
protected function readXmlNodes(\SimpleXMLElement $element): array
    {
        $arrayElements = [];
        foreach ($element as $name => $node) {
            if ($name == "defaults") {
                continue;
            }
            $arrayElement = [];
            $arrayElement["type"] = $name;
            $arrayElement["attributes"] = $this->readAttributesArray($node);
            $details = $this->readXmlNodes($node);
            if (!empty($details)) {
                $arrayElement["details"] = $details;
            }
            $arrayElements[] = $arrayElement;
        }

        return $arrayElements;
    }
366523
public static function array_to_xml($array, &$xml)
	{
		foreach($array as $key => $value) {
			if(is_array($value)) {
				if(!is_numeric($key)){
					$subnode = $xml->addChild("$key");
					self::array_to_xml($value, $subnode);
				} elseif ($key == 0) {
					self::array_to_xml($value, $xml);
				} else {
					$name = $xml->getName();
					$subnode = $xml->xpath("..")[0]->addChild("$name");
					self::array_to_xml($value, $subnode);
				}
			} else {
				$xml->addChild("$key","$value");
			}
		}
	}
680881
public static function toArray(\SimpleXMLElement $xml, $namespace = null)
    {
        if ($namespace !== null) {

            $namespaces = $xml->getNamespaces();

            if (false === isset($namespaces[$namespace])) {
                throw new \OutOfBoundsException('namespace [' . $namespace . '] not found');
            }

            $xml = $xml->children($namespaces[$namespace]);
        }

        return Json::decode(Json::encode($xml), true);
    }
670774
static function simpleXmlToStdClass(SimpleXMLElement &$source)
  {
    $res = new StdClass;
    $children = false;
    foreach ($source as $key => $value) {
      if (isset($res->$key)) {
        if (!is_array($res->$key)) {
          $res->$key = array($res->$key);
        }
        $ref = &$res->$key;
        $ref[] = CPS_Response::simpleXmlToStdClass($value);
      } else {
        $res->$key = CPS_Response::simpleXmlToStdClass($value);
      }
      $children = true;
    }
    if (!$children)
      return (string)$source;
    return $res;
  }
997999
protected function childToArray(SimpleXmlElement $xml, $name)
    {
        if (!isset($xml->{$name})) {
            return array();
        }

        return $xml->{$name}->toPhpValue('array');
    }
668397
public static function xml2array($xmlstring)
    {
        $result = [];
        self::normalizeSimpleXML(simplexml_load_string($xmlstring, null, LIBXML_NOCDATA), $result);

        return $result;
    }
319610
private function _parseOptions(SimpleXMLElement $options)
    {
        $array = array();

        /* @var $option SimpleXMLElement */
        foreach ($options as $option) {
            if ($option->count()) {
                $value = $this->_parseOptions($option->children());
            } else {
                $value = (string) $option;
            }

            $attr = $option->attributes();

            if (isset($attr->name)) {
                $array[(string) $attr->name] = $value;
            } else {
                $array[] = $value;
            }
        }

        return $array;
    }
423376
public static function getArray($var)
    {
        if (is_null($var) || empty($var)) {
            return [];
        }

        foreach ($var as $value) {
            if ((gettype($value) == 'object')
                && (get_class($value) == 'SimpleXMLElement')
            ) {
                return (array) $var;
            } elseif (!is_array($value)) {
                return [$var];
            }
        }

        return $var;
    }
414009
public function toArray()
    {
        if (!$this->xml and $this->xml_data) {
            $this->loadXML($this->xml_data);
        }
        if (!$this->xml) {
            return false;
        }
        if (!$this->arreglo) {
            $this->arreglo = $this->xml->toArray();
        }
        return $this->arreglo;
    }
1357067
public static function toArray(string $xml): array
    {
        $backup = libxml_disable_entity_loader(true);
        $result = static::xml2Data(simplexml_load_string(
            $xml,
            'SimpleXMLElement',
            LIBXML_COMPACT | LIBXML_NOCDATA | LIBXML_NOBLANKS
        ));
        libxml_disable_entity_loader($backup);
        return $result;
    }
963735
protected function convertXmlToArray($xml)
    {
        libxml_disable_entity_loader(true);
        return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    }
1276236
private function xmlToElements($xml)
    {
        //====================================================================//
        // Convert XML to Object Recursively
        try {
            $result = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOERROR);
        } catch (Exception $ex) {
            $this->fault = $ex->getMessage();

            return false;
        }

        return $result;
    }
221535
public static function XML2Array($xmlString)
    {
        try {
            $xml    = simplexml_load_string($xmlString, "SimpleXMLElement",
                LIBXML_NOCDATA);
            $json   = json_encode($xml);
            $result = json_decode($json, TRUE);
        } catch (\Exception $ex) {
            $result = '';
        }
        return $result;
    }
844601
protected function xmlDeserialize($xml)
    {
        $array = [];

        if (!$xml instanceof SimpleXMLElement)
        {
            $xml = new SimpleXMLElement($xml);
        }

        foreach ($xml->children() as $key => $child)
        {
            $value = (string) $child;
            $_children = $this->xmlDeserialize($child);
            $_push = ( $_hasChild = ( count($_children) > 0 ) ) ? $_children : $value;

            if ( $_hasChild && !empty($value) && $value !== '' )
            {
                $_push[] = $value;
            }

            $array[$key] = $_push;
        }

        return $array;
    }
1144014
private static function xmlToArray(
        \SimpleXMLElement $xml,
        $ns = null,
        $nesting = 0
    ) {
        $result = [];
        $children = $xml->children($ns, true);

        foreach ($children as $name => $child) {
            $attributes = (array) $child->attributes($ns, true);
            if (!isset($result[$name])) {
                $childArray = self::xmlToArray($child, $ns, $nesting + 1);
                $result[$name] = $attributes
                    ? array_merge($attributes, $childArray)
                    : $childArray;
                continue;
            }
            // A child element with this name exists so we're assuming
            // that the node contains a list of elements
            if (!is_array($result[$name])) {
                $result[$name] = [$result[$name]];
            } elseif (!isset($result[$name][0])) {
                // Convert the first child into the first element of a numerically indexed array
                $firstResult = $result[$name];
                $result[$name] = [];
                $result[$name][] = $firstResult;
            }
            $childArray = self::xmlToArray($child, $ns, $nesting + 1);
            if ($attributes) {
                $result[$name][] = array_merge($attributes, $childArray);
            } else {
                $result[$name][] = $childArray;
            }
        }

        // Extract text from node
        $text = trim((string) $xml);
        if ($text === '') {
            $text = null;
        }

        // Process attributes
        $attributes = (array) $xml->attributes($ns, true);
        if ($attributes) {
            if ($text !== null) {
                $result['value'] = $text;
            }
            $result = array_merge($attributes, $result);
        } elseif ($text !== null) {
            $result = $text;
        }

        // Make sure we're always returning an array
        if ($nesting == 0 && !is_array($result)) {
            $result = [$result];
        }

        return $result;
    }