@param $userXml

@return array
438350
private function getToolsKeys($userXml)
    {
        $melisCoreUser = $this->getServiceLocator()->get('MelisCoreUser');
        $melisAppConfig = $this->getServiceLocator()->get('MelisCoreConfig');
        $melisKeys = $this->getConfig()->getMelisKeys();

        $appConfigPaths = $this->getMelisKeyPaths();
        $tools = [];
        foreach ($appConfigPaths as $idx => $path) {
            $appConfigPath = $melisKeys[$path];
            $appsConfig = $melisAppConfig->getItem($appConfigPath);
            $orderInterface = $melisAppConfig->getOrderInterfaceConfig($path);
            $selectedTools = $melisCoreUser->isItemRightChecked($userXml, self::MELIS_PLATFORM_TOOLS_PREFIX, $path);


            // tool category
            $tools[$idx] = [
                'key' => $path,
                'title' => $appsConfig['conf']['name'] ?? $path,
                'lazy' => false,
                'children' => [],
                'selected' => $selectedTools,
                'iconTab' => '',
                'melisData' => [
                    'colorSelected' => '#99C975',
                ],
            ];

            // first level, sections
            $appCtr = 0;
            foreach ($appsConfig['interface'] as $appKey => $appSection) {

                $selectedTools = $melisCoreUser->isItemRightChecked($userXml, self::MELIS_PLATFORM_TOOLS_PREFIX, $appKey);
                $tools[$idx]['children'][$appCtr] = [
                    'key' => $appKey,
                    'title' => $appSection['conf']['name'] ?? $appKey,
                    'lazy' => false,
                    'children' => [],
                    'selected' => $selectedTools,
                    'iconTab' => '',
                    'melisData' => [
                        'colorSelected' => '#99C975',
                    ],
                ];

                // Second level, tools
                $appToolCtr = 0;
                if (isset($appSection['interface'])) {
                    foreach ($appSection['interface'] as $toolKey => $toolName) {
                        $selectedTools = $melisCoreUser->isItemRightChecked($userXml, self::MELIS_PLATFORM_TOOLS_PREFIX, $toolKey);
                        $icon = $toolName['conf']['icon'] ?? null;

                        if ($icon) {
                            $tools[$idx]['children'][$appCtr]['children'][$appToolCtr] = [
                                'key' => $toolKey,
                                'title' => $toolName['conf']['name'] ?? $toolKey,
                                'children' => [],
                                'lazy' => false,
                                'selected' => $selectedTools,
                                'iconTab' => '',
                                'melisData' => [
                                    'colorSelected' => '#99C975',
                                ],
                            ];
                        }
                        $appToolCtr++;
                    }
                    $appCtr++;
                }

            }

        }

        // Reordering sections
        $sections = $tools;
        $toolsOrdered = [];
        foreach ($orderInterface as $orderKeySection => $sectionTools) {
            if (!empty($sections[$orderKeySection])) {
                if (empty($toolsOrdered[$orderKeySection])) {
                    $toolsOrdered[$orderKeySection] = [];
                }
                $toolsOrdered[$orderKeySection] = $tools[$orderKeySection];
            }
        }
        foreach ($sections as $keyInterfaceSection => $childinterface) {
            if (empty($toolsOrdered[$keyInterfaceSection])) {
                $toolsOrdered[$keyInterfaceSection] = [];
            }
            $toolsOrdered[$keyInterfaceSection] = $tools[$keyInterfaceSection];

        }

        // Reordering tools inside sections
        if ($toolsOrdered) {
            foreach ($toolsOrdered as $keySection => $toolsSection) {
                $sectionOrderInterface = [];
                if (!empty($orderInterface[$keySection])) {
                    $sectionOrderInterface = $orderInterface[$keySection];
                }
                $toolsSectionOrdered = [];

                if (!empty($sectionOrderInterface)) {
                    foreach ($sectionOrderInterface as $orderKey) {
                        if (!empty($tools[$keySection]['children'][$orderKey])) {
                            $toolsOrdered[$keySection]['children'][$orderKey] = $tools[$keySection]['children'][$orderKey];
                        }
                    }

                    foreach ($tools[$keySection]['children'] as $keyInterface => $childinterface) {
                        $toolsOrdered[$keySection]['children'][$keyInterface] = $childinterface;
                    }
                }
            }
        }

        $finalToolsOrdered = [];
        foreach ($toolsOrdered as $key => $sectionTool) {
            $toolsTmp = [];
            if (!empty($sectionTool['children'])) {
                $toolsTmp = $sectionTool['children'];
            }
            $newTools = [];

            foreach ($toolsTmp as $keyTool => $tool) {
                $newTools[] = $tool;
            }
            $sectionTool['children'] = $newTools;
            $finalToolsOrdered[] = $sectionTool;
        }

        return $finalToolsOrdered;

    }
649395
public function parseFromXml($strXml)
    {
        $this->rules = array();
        $xml = simplexml_load_string($strXml);
        if (!isset($xml->Rule)) return;
        $this->rules = array();
        foreach ($xml->Rule as $rule) {
            $id = strval($rule->ID);
            $prefix = strval($rule->Prefix);
            $status = strval($rule->Status);
            $actions = array();
            foreach ($rule as $key => $value) {
                if ($key === 'ID' || $key === 'Prefix' || $key === 'Status') continue;
                $action = $key;
                $timeSpec = null;
                $timeValue = null;
                foreach ($value as $timeSpecKey => $timeValueValue) {
                    $timeSpec = $timeSpecKey;
                    $timeValue = strval($timeValueValue);
                }
                $actions[] = new LifecycleAction($action, $timeSpec, $timeValue);
            }
            $this->rules[] = new LifecycleRule($id, $prefix, $status, $actions);
        }
        return;
    }
769060
protected static function xml2Data($xml)
    {
        $result = null;
        is_object($xml) && $xml = (array)$xml;
        if (is_array($xml)) {
            foreach ($xml as $key => $value) {
                $res = static::xml2Data($value);
                if (('@attributes' === $key) && ($key)) {
                    $result = $res;
                } else {
                    $result[$key] = $res;
                }
            }
        } else {
            $result = $xml;
        }
        return $result;
    }
746409
private function _XML2Array($xml)
    {
        $envelope = simplexml_load_string($xml, "SimpleXMLElement", 0, 'http://schemas.xmlsoap.org/soap/envelope/');
        foreach ($envelope->Body as $response) {
            foreach ($response->children('http://Hps.Exchange.PosGateway') as $item) {
                return $item;
            }
        }
        return null;
    }
1033727
public function getChildren(User $user)
    {
        $returnArray = array();
        foreach ($this->userList as $u) {
            /** @var $u User */
            if ($u->getParent() == $user->getUsername()) {
                $returnArray[] = $u;
                $returnArray = array_merge($returnArray, $this->getChildren($u));
            }
        }
        return $returnArray;
    }
857865
public function fromXSD($xsd): array
    {
        if (!$this->isEmptyValue($xsd)) {
            return $this->fromXml($xsd->output);
        }

        return $this->result;

    }
1150242
public static function xml2array($xml)
    {
        $arr = [];
        if (!empty($xml)) {
            if (is_string($xml)) {
                $xml = simplexml_load_string($xml);
            }
            foreach ($xml->attributes() as $a) {
                $arr['@'.$a->getName()] = strval($a);
            }
            foreach ($xml->children() as $r) {
                if (count($r->children()) == 0) {
                    $arr[$r->getName()] = strval($r);
                } else {
                    $arr[$r->getName()][] = self::xml2array($r);
                }
            }
        }
        return $arr;
    }
467005
protected function convertXmlToArray($xml)
    {
        // Convert the response to an array via a 3-way conversion:
        // - create a simplexml object
        // - convert that to json
        // - convert json to array
        libxml_use_internal_errors(true);
        if (!($result = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA))) {
            $this->raiseLibxmlError(libxml_get_errors());
        }

        if (!($result = json_encode($result))) {
            $this->raiseJsonError();
        }
        if (($result = json_decode($result, true)) === null) {
            $this->raiseJsonError();
        }

        return $result;
    }
338847
public static function get_users_in_context(userlist $userlist) {
        $context = $userlist->get_context();

        if (!is_a($context, \context_module::class)) {
            return;
        }

        $params = [
            'lesson' => 'lesson',
            'modulelevel' => CONTEXT_MODULE,
            'contextid' => $context->id,
        ];

        // Mapping of lesson tables which may contain user data.
        $joins = [
            'lesson_attempts',
            'lesson_branch',
            'lesson_grades',
            'lesson_overrides',
            'lesson_timer',
        ];

        foreach ($joins as $join) {
            $sql = "
                SELECT lx.userid
                  FROM {lesson} l
                  JOIN {modules} m
                    ON m.name = :lesson
                  JOIN {course_modules} cm
                    ON cm.instance = l.id
                   AND cm.module = m.id
                  JOIN {context} ctx
                    ON ctx.instanceid = cm.id
                   AND ctx.contextlevel = :modulelevel
                  JOIN {{$join}} lx
                    ON lx.lessonid = l.id
                 WHERE ctx.id = :contextid";

            $userlist->add_from_sql('userid', $sql, $params);
        }
    }
1048532
protected function parseXML($xml){
        $this->destinationList = array();
        if (!$xml){
            return false;
        }

        $i = 0;
        foreach ($xml->DestinationList->children() as $item) {
            $this->destinationList[$i]['DeliveryChannel'] = (string)$item->DeliveryChannel;

            foreach ($item->AttributeList->children() as $member) {
                $this->destinationList[$i]['AttributeList'][(string)$member->Key] = (string)$member->Value;
            }

            $i++;
        }
    }
1097116
static public function xmlToArray($xml)
    {
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $values;
    }
1053301
public static function xmlToArray($xml) {
        $arr = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $arr;
    }
202125
public function parseXML($xml)
    {
        $document = new \DOMDocument();

        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $result = $document->loadXML($xml);
        /** @var \libXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        if (true !== $result) {
            $message = [];
            foreach ($errors as $error) {
                $message[] = sprintf(
                    '%d. [%s] %s in on line %d in position %d',
                    count($message) + 1,
                    $error->code,
                    str_replace(["\n", "\r"], '', $error->message),
                    $error->line,
                    $error->column
                );
            }
            throw new RuntimeException('Can not parse XML: ' . implode('; ', $message));
        }

        return $this->parseDocument($document);
    }
572925
public static function parseXMLToArray($xml)
    {
        if (empty($xml))
            return false;

        $data = array();
        $data[$xml['Stage']->getName()] = $xml['Stage']->__toString();
        foreach ($xml as $element) {
            if ($element->children()) {
                foreach ($element as $child) {
                    if ($child->attributes()) {
                        foreach ($child->attributes() as $key => $value) {
                            $data[$element->getName()][$child->getName()][$key] = $value->__toString();
                        }
                    } else {
                        $data[$element->getName()][$child->getName()] = $child->__toString();
                    }
                }
            } else {
                $data[$element->getName()] = $element->__toString();
            }
        }

        $data = json_encode($data);
        if(JsonValidator::validate($data))
            return $data;

        return false;
    }
577203
private function validateValue($element, $userInput) : array
    {
        $valid = true;
        $value = null;
        $typedValue = null;

        if ($element->isRequired() && is_null($userInput)) {
            $valid = false;
        }

        if ($element->getPrimitiveType() && !is_null($userInput)) {
            $typedValue = $this->validateType($userInput, $element->getPrimitiveType());
            if (is_null($typedValue)) {
                $valid = false;
            } else {
                $value = $typedValue;
            }
        } else {
            $value = $userInput;
        }

        if (method_exists($element, 'transformValue') && $value) {
            $value = $element->transformValue($value);
        }

        if (method_exists($element, 'isValid') && $valid == true && $element->getValue()) {
            $valid = $element->isValid();
        }

        if (!$valid) {
            $value = null;
        }

        return [$valid, $value, $typedValue];
    }
1307027
public function extract($xmltext)
	{
		try {
			$xml = new DOMDocument();
			$xml->loadXML($xmltext);
			$array_e = $xml->getElementsByTagName('Encrypt');
			$array_a = $xml->getElementsByTagName('ToUserName');
			$encrypt = $array_e->item(0)->nodeValue;
			$tousername = $array_a->item(0)->nodeValue;
			return array(0, $encrypt, $tousername);
		} catch (Exception $e) {
			//print $e . "\n";
			return array(ErrorCode::$ParseXmlError, null, null);
		}
	}
281571
public static function arrayFromXml($xml)
    {
        $document = new DOMDocument('1.0', 'UTF-8');
        $document->loadXML($xml);

        $root = $document->documentElement->nodeName;

        return Util::delimiterToCamelCaseArray([
            $root => self::_nodeToValue($document->childNodes->item(0)),
        ]);
    }