Processes entry node.

@param array $xmlArray An array of simple xml elements

@return array
331367
protected function processEntryNode($xmlArray)
    {
        $entry = [];
        $entryItem = $xmlArray[Resources::ENTRY];

        if (is_array($entryItem)) {
            foreach ($xmlArray[Resources::ENTRY] as $entryXmlInstance) {
                $entryInstance = new Entry();
                $entryInstance->fromXml($entryXmlInstance);
                $entry[] = $entryInstance;
            }
        } else {
            $entryInstance = new Entry();
            $entryInstance->fromXml($entryItem);
            $entry[] = $entryInstance;
        }

        return $entry;
    }
598103
protected function fromArray(array $nodeArray)
    {

        $node = $this->nodeCreator->makeNode();

        $node->id = $nodeArray['id'];
        $node->setPath($nodeArray['path']);
        $node->setMenuTitle($nodeArray['menu_title']);
        $node->setTitle($nodeArray['title']);
        $node->setContent($nodeArray['content']);
        $node->parent_id = 'parent-id-'.$nodeArray['id'];
        $node->route_name = $nodeArray['routeName'];

        return $node;

    }
595830
public static function arrayToXML(array $array, $key_override = null)
    {
        $xml = '';
        foreach ($array as $key => $element) {
            if (is_array($element)) {
                //recurse and replace.
                if (self::isAssoc($element)) {
                    $element = self::arrayToXML($element);
                } else {
                    //Dirty dirty hack to make the 1.x branch work for tracking categories
                    //This is the only instance in the whole app of 'Tracking' so should be ok for BC.
                    if ($key === 'Tracking') {
                        $element = self::arrayToXML($element, 'TrackingCategory');
                    } else {
                        $element = self::arrayToXML($element, self::singularize($key));
                    }
                }
            } else {
                //Element escaping for the http://www.w3.org/TR/REC-xml/#sec-predefined-ent
                //Full DOMDocument not really necessary as we don't use attributes (which are more strict)
                $element = strtr(
                    $element,
                    [
                        '<' => '&lt;',
                        '>' => '&gt;',
                        '"' => '&quot;',
                        "'" => '&apos;',
                        '&' => '&amp;',
                    ]
                );
            }

            if ($key_override !== null) {
                $key = $key_override;
            }
            $xml .= sprintf('<%1$s>%2$s</%1$s>', $key, $element);
        }

        return $xml;
    }
373988
protected function arrayToDOM($array, $rootElement, $charset = null)
    {
        foreach ($array as $key => $value) {
            if (is_numeric($key)) {
                $key = $rootElement->nodeName;

                // Books => Book
                if (substr($key, -1, 1) === 's') {
                    $key = substr($key, 0, strlen($key) - 1);
                }
            }

            $element = $rootElement->ownerDocument->createElement($key);
            if (is_array($value)) {
                if (!empty($value)) {
                    $element = $this->arrayToDOM($value, $element, $charset);
                }
            } elseif (is_string($value)) {
                $charset = $charset ? $charset : 'utf-8';
                if (function_exists('iconv') && strcasecmp($charset, 'utf-8') !== 0 && strcasecmp($charset, 'utf8') !== 0) {
                    $value = iconv($charset, 'UTF-8', $value);
                }
                $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
                $child = $element->ownerDocument->createCDATASection($value);
                $element->appendChild($child);
            } elseif ($value instanceof \DateTimeInterface) {
                $element->setAttribute('type', 'xsd:dateTime');
                $child = $element->ownerDocument->createTextNode($value->format(\DateTime::ISO8601));
                $element->appendChild($child);
            } else {
                $child = $element->ownerDocument->createTextNode($value);
                $element->appendChild($child);
            }
            $rootElement->appendChild($element);
        }

        return $rootElement;
    }
1366217
private static function deserializeAlternateVerificationKeys($xmlElement)
    {
        $result = [];

        foreach ($xmlElement->children() as $child) {
            $result[] = self::deserializeTokenVerificationKey($child);
        }

        return $result;
    }
421730
public function arr2xmldb_structure($xmlarr) {

        global $CFG;

        $result = true;

        // Debug the structure
        // traverse_xmlize($xmlarr);                   //Debug
        // print_object ($GLOBALS['traverse_array']);  //Debug
        // $GLOBALS['traverse_array']="";              //Debug

        // Process structure attributes (path, comment and version)
        if (isset($xmlarr['XMLDB']['@']['PATH'])) {
            $this->path = trim($xmlarr['XMLDB']['@']['PATH']);
        } else {
            $this->errormsg = 'Missing PATH attribute';
            $this->debug($this->errormsg);
            $result = false;
        }
        // Normalize paths to compare them.
        $filepath = realpath($this->name); // File path comes in name.
        $filename = basename($filepath);
        $normalisedpath = $this->path;
        if ($CFG->admin !== 'admin') {
            $needle = 'admin/';
            if (strpos($this->path, $needle) === 0) {
                $normalisedpath = substr_replace($this->path, "$CFG->admin/", 0, strlen($needle));
            }
        }
        $structurepath = realpath($CFG->dirroot . DIRECTORY_SEPARATOR . $normalisedpath . DIRECTORY_SEPARATOR . $filename);
        if ($filepath !== $structurepath) {
            $relativepath = dirname(str_replace(realpath($CFG->dirroot) . DIRECTORY_SEPARATOR, '', $filepath));
            $this->errormsg = 'PATH attribute does not match file directory: ' . $relativepath;
            $this->debug($this->errormsg);
            $result = false;
        }
        if (isset($xmlarr['XMLDB']['@']['VERSION'])) {
            $this->version = trim($xmlarr['XMLDB']['@']['VERSION']);
        } else {
            $this->errormsg = 'Missing VERSION attribute';
            $this->debug($this->errormsg);
            $result = false;
        }
        if (isset($xmlarr['XMLDB']['@']['COMMENT'])) {
            $this->comment = trim($xmlarr['XMLDB']['@']['COMMENT']);
        } else if (!empty($CFG->xmldbdisablecommentchecking)) {
            $this->comment = '';
        } else {
            $this->errormsg = 'Missing COMMENT attribute';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Iterate over tables
        if (isset($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'])) {
            foreach ($xmlarr['XMLDB']['#']['TABLES']['0']['#']['TABLE'] as $xmltable) {
                if (!$result) { //Skip on error
                    continue;
                }
                $name = trim($xmltable['@']['NAME']);
                $table = new xmldb_table($name);
                $table->arr2xmldb_table($xmltable);
                $this->tables[] = $table;
                if (!$table->isLoaded()) {
                    $this->errormsg = 'Problem loading table ' . $name;
                    $this->debug($this->errormsg);
                    $result = false;
                }
            }
        } else {
            $this->errormsg = 'Missing TABLES section';
            $this->debug($this->errormsg);
            $result = false;
        }

        // Perform some general checks over tables
        if ($result && $this->tables) {
            // Check tables names are ok (lowercase, a-z _-)
            if (!$this->checkNameValues($this->tables)) {
                $this->errormsg = 'Some TABLES name values are incorrect';
                $this->debug($this->errormsg);
                $result = false;
            }
            // Compute prev/next.
            $this->fixPrevNext($this->tables);
            // Order tables
            if ($result && !$this->orderTables($this->tables)) {
                $this->errormsg = 'Error ordering the tables';
                $this->debug($this->errormsg);
                $result = false;
            }
        }

        // Set some attributes
        if ($result) {
            $this->loaded = true;
        }
        $this->calculateHash();
        return $result;
    }
786199
public function &buildArray($inputXml)
    {
        $this->init();

        if (is_string($inputXml)) {
            $this->xml = $this->createDOMDocument();
            $parsed = $this->xml->loadXML($inputXml);
            if ( ! $parsed) {
                throw new \Exception('[Transformer] Error parsing the XML string.');
            }
        } elseif ($inputXml instanceof \DOMDocument) {
            $this->xml = $inputXml;
        } else {
            throw new \Exception('[Transformer] The input XML object should be of type: DOMDocument but got instead ['.gettype($inputXml).'].');
        }
        
        // Convert the XML to an array, starting with the root node
        $docNodeName = $this->xml->documentElement->nodeName;
        $array[$docNodeName] = $this->convert($this->xml->documentElement);
        
        // Add namespacing information to the root node
        if ( ! empty($this->namespaces)) {
            if ( ! isset($array[$docNodeName][$this->config['attributesKey']])) {
                $array[$docNodeName][$this->config['attributesKey']] = array();
            }
            foreach ($this->namespaces as $uri => $prefix) {
                if ($prefix) {
                    $prefix = self::ATTRIBUTE_NAMESPACE_SEPARATOR . $prefix;
                }
                $array[$docNodeName][$this->config['attributesKey']][self::ATTRIBUTE_NAMESPACE . $prefix] = $uri;
            }
        }
        return $array;
    }
955667
protected function convertXmlObjectToArray($xml)
    {
        $array = (array) $xml;

        if (count($array) == 0 && ! is_array($xml)) {

            $array = [ (string) $xml ];
        }

        if (is_array($array)) {

            foreach ($array as $key => $value) {

                if (is_object($value)) {

                    if (strpos(get_class($value), "SimpleXML") !== false) {

                        $array[ $key ] = $this->convertXmlObjectToArray($value);

                    } else {

                        $array[ $key ] = $this->convertXmlObjectToArray( (array) $value );
                    }

                } elseif (is_array($value)) {

                    $array[ $key ] = $this->convertXmlObjectToArray($value);
                }
            }
        }

        return $array;
    }
1157320
protected static function _toArray($xml, &$parentData, $ns, $namespaces)
    {
        $data = [];

        foreach ($namespaces as $namespace) {
            foreach ($xml->attributes($namespace, true) as $key => $value) {
                if (!empty($namespace)) {
                    $key = $namespace . ':' . $key;
                }
                $data['@' . $key] = (string)$value;
            }

            foreach ($xml->children($namespace, true) as $child) {
                static::_toArray($child, $data, $namespace, $namespaces);
            }
        }

        $asString = trim((string)$xml);
        if (empty($data)) {
            $data = $asString;
        } elseif (strlen($asString) > 0) {
            $data['@'] = $asString;
        }

        if (!empty($ns)) {
            $ns .= ':';
        }
        $name = $ns . $xml->getName();
        if (isset($parentData[$name])) {
            if (!is_array($parentData[$name]) || !isset($parentData[$name][0])) {
                $parentData[$name] = [$parentData[$name]];
            }
            $parentData[$name][] = $data;
        } else {
            $parentData[$name] = $data;
        }
    }
387742
public function setArray($XMLArray){
		if (is_array($XMLArray) && count($XMLArray) != 0){
			$this->XMLArray = $XMLArray;
			$this->arrayOK = true;
		}else{
			$this->arrayOK = false;
		}
		return $this->arrayOK;
	}
419889
public static function xmlToArray($xml, $format = self::XML_GROUP) {
		if (is_string($xml)) {
			$xml = @simplexml_load_string($xml);
		}

		if (count($xml->children()) <= 0) {
			return (string)$xml;
		}

		$array = array();

		foreach ($xml->children() as $element => $node) {
			$data = array();

			if (!isset($array[$element])) {
				$array[$element] = "";
			}

			if (!$node->attributes() || $format === self::XML_NONE) {
				$data = self::xmlToArray($node, $format);

			} else {
				switch ($format) {
					case self::XML_GROUP:
						$data = array(
							'attributes' => array(),
							'value' => (string)$node
						);

						if (count($node->children()) > 0) {
							$data['value'] = self::xmlToArray($node, $format);
						}

						foreach ($node->attributes() as $attr => $value) {
							$data['attributes'][$attr] = (string)$value;
						}
					break;

					case self::XML_MERGE:
					case self::XML_OVERWRITE:
						if ($format === self::XML_MERGE) {
							if (count($node->children()) > 0) {
								$data = $data + self::xmlToArray($node, $format);
							} else {
								$data['value'] = (string)$node;
							}
						}

						foreach ($node->attributes() as $attr => $value) {
							$data[$attr] = (string)$value;
						}
					break;
				}
			}

			if (count($xml->{$element}) > 1) {
				$array[$element][] = $data;
			} else {
				$array[$element] = $data;
			}
		}

		return $array;
	}
996354
private function arrayToXml(array &$data, SimpleXMLElement $xmlData)
    {
        foreach ($data as $key => $value) {
            if (\is_array($value)) {
                if (\is_numeric($key)) {
                    $key = 'sequential-item';
                }
                $subnode = $xmlData->addChild($key);

                $this->arrayToXml($value, $subnode);
            } else {
                $subnode = $xmlData->addChild("$key", "$value");

                $type = \gettype($value);
                if ('array' !== $type) {
                    $subnode->addAttribute('type', $type);
                }
            }
        }
    }
648234
private function simpleXmlToArray(\SimpleXMLElement $xmlObject): array
    {
        $array = [];
        foreach ($xmlObject->children() as $node) {
            $array[$node->getName()] = is_array($node) ? $this->simpleXmlToArray($node) : (string) $node;
        }

        return $array;
    }
964842
public function fromXml(\SimpleXMLElement $entryXml)
    {
        Validate::notNull($entryXml, 'entryXml');

        $this->attributes = (array) $entryXml->attributes();
        $entryArray = (array) $entryXml;

        if (array_key_exists(Resources::AUTHOR, $entryArray)) {
            $this->author = $this->processAuthorNode($entryArray);
        }

        if (array_key_exists(Resources::CATEGORY, $entryArray)) {
            $this->category = $this->processCategoryNode($entryArray);
        }

        if (array_key_exists('content', $entryArray)) {
            $content = new Content();
            $content->fromXml($entryArray['content']);
            $this->content = $content;
        }

        if (array_key_exists(Resources::CONTRIBUTOR, $entryArray)) {
            $this->contributor = $this->processContributorNode($entryArray);
        }

        if (array_key_exists('id', $entryArray)) {
            $this->id = (string) $entryArray['id'];
        }

        if (array_key_exists(Resources::LINK, $entryArray)) {
            $this->link = $this->processLinkNode($entryArray);
        }

        if (array_key_exists('published', $entryArray)) {
            $this->published = $entryArray['published'];
        }

        if (array_key_exists('rights', $entryArray)) {
            $this->rights = $entryArray['rights'];
        }

        if (array_key_exists('source', $entryArray)) {
            $source = new Source();
            $source->parseXml($entryArray['source']->asXML());
            $this->source = $source;
        }

        if (array_key_exists('title', $entryArray)) {
            $this->title = $entryArray['title'];
        }

        if (array_key_exists('updated', $entryArray)) {
            $this->updated = \DateTime::createFromFormat(
                \DateTime::ATOM,
                (string) $entryArray['updated']
            );
        }
    }
80521
public static function buildXml(&$xml, $array) {
		if (is_array($array)) {
			foreach ($array as $key => $value) {
				// XML_NONE
				if (!is_array($value)) {
					$xml->addChild($key, $value);
					continue;
				}

				// Multiple nodes of the same name
				if (isset($value[0])) {
					foreach ($value as $kValue) {
						if (is_array($kValue)) {
							self::buildXml($xml, array($key => $kValue));
						} else {
							$xml->addChild($key, $kValue);
						}
					}

				// XML_GROUP
				} else if (isset($value['attributes'])) {
					if (is_array($value['value'])) {
						$node = $xml->addChild($key);
						self::buildXml($node, $value['value']);
					} else {
						$node = $xml->addChild($key, $value['value']);
					}

					if (!empty($value['attributes'])) {
						foreach ($value['attributes'] as $aKey => $aValue) {
							$node->addAttribute($aKey, $aValue);
						}
					}

				// XML_MERGE
				} else if (isset($value['value'])) {
					$node = $xml->addChild($key, $value['value']);
					unset($value['value']);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addAttribute($aKey, $aValue);
							}
						}
					}

				// XML_OVERWRITE
				} else {
					$node = $xml->addChild($key);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addChild($aKey, $aValue);
							}
						}
					}
				}
			}
		}

		return $xml;
	}
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);
		}
	}
794406
private static function deserializeRequiredClaims($xmlElement)
    {
        $result = [];

        foreach ($xmlElement->children() as $child) {
            if (!isset($child->ClaimType)) {
                throw new  \RuntimeException("The TokenClaim must contains a 'ClaimType' element");
            }

            $claim = new TokenClaim((string) $child->ClaimType);

            if (isset($child->ClaimValue)) {
                $claim->setClaimValue((string) $child->ClaimValue);
            }
            $result[] = $claim;
        }

        return $result;
    }