Formatea el xml a formato pretty manteniendo los saltos de linea
@param SimpleXMLElement $simpleXMLElement
@return type
976180
function formatXml(SimpleXMLElement $simpleXMLElement)
    {
        $xmlDocument = new DOMDocument('1.0');
        $xmlDocument->preserveWhiteSpace = false;
        $xmlDocument->formatOutput = true;
        $xmlDocument->loadXML($simpleXMLElement->asXML());

        return $xmlDocument->saveXML();
    }
820
public function xml2array(\SimpleXMLElement $xml)
    {
        $arr = array();
        foreach ($xml as $element) {
            $tag = $element->getName();
            $e = get_object_vars($element);
            if (!empty($e)) {
                $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
            } else {
                $arr[$tag] = trim($element);
            }
        }

        return $arr;
    }
797386
protected static function parseAtom(\SimpleXMLElement $xml)
    {
        if (!isset($xml->entry)) {
            return false;
        }

        $url = '';

        foreach ($xml->link as $link) {
            $attributes = $link->attributes();

            if (empty($attributes->href) || ((string) $attributes->rel === 'self')) {
                continue;
            }
            $url = (string) $attributes->href;
            break;
        }

        return [
            'url' => $url,
            'items' => self::getAtomEntries($xml->entry),
        ];
    }
172368
public static function parseElementXml(SimpleXMLElement $xml){

        $attributes = array();
        foreach($xml->attributes() as $name => $value){
            $attributes[$name] = (string) $value;
        }

        $returnValue = array(
            'qtiClass' => $xml->getName()
        );

        if(count($attributes)){
            $returnValue['attributes'] = $attributes;
        }

        return $returnValue;
    }
1251503
private function parseDiffXml( SimpleXMLElement $xml )
    {
        $newTables = array();
        foreach ( $xml->{'new-tables'}->table as $table )
        {
            $tableName = (string) $table->name;
            $newTables[$tableName] = $this->parseTable( $table );
        }

        $changedTables = array();
        foreach ( $xml->{'changed-tables'}->table as $table )
        {
            $tableName = (string) $table->name;
            $changedTables[$tableName] = $this->parseChangedTable( $table );
        }

        $removedTables = array();
        foreach ( $xml->{'removed-tables'}->table as $table )
        {
            $tableName = (string) $table->name;
            if ( (string) $table->removed == 'true' )
            {
                $removedTables[$tableName] = true;
            }
        }

        return new ezcDbSchemaDiff( $newTables, $changedTables, $removedTables );
    }
341493
protected function elementToArray(\SimpleXMLElement $element): array
    {
        $result = [];
        foreach ($element->xpath('*') as $node) {
            if (count($node->xpath('*')) > 0) {
                $value = $this->elementToArray($node);
            } else {
                $value = strval($node);
            }
            $result = array_merge_recursive($result, [$node->getName() => $value]);
        }

        return $result;
    }
620140
private function _asXml($simpleXml)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->loadXML($simpleXml->asXML());
        $dom->formatOutput = true;

        return $dom->saveXML();
    }
470965
public function singlePcmlToArray(\SimpleXmlElement $dataElement)
    {
        $tagName = $dataElement->getName();

        // get attributes of this element.
        $attrs = $dataElement->attributes();

        // both struct and data have name, count (optional), usage
        $name = (isset($attrs['name'])) ? (string) $attrs['name'] : '';
        $count = (isset($attrs['count'])) ? (string) $attrs['count'] : '';
        $usage = (isset($attrs['usage'])) ? (string) $attrs['usage'] : '';
        $structName = (isset($attrs['struct'])) ? (string) $attrs['struct'] : '';

        // fill this if we have a struct
        $subElements = array();

        // should all be data
        if ($tagName == 'data') {

            $type = (isset($attrs['type'])) ? (string) $attrs['type'] : '';

            // if a struct then we need to recurse.
            if ($type != 'struct') {

                // regular type (char, int...), not a struct, so the data element's name is just 'name'.
                $nameName = 'Name';
            } else {
                // it IS a struct.

                // old toolkit uses DSName for a data structure's name.
                $nameName = 'DSName';

                $theStruct = null; // init

                // look for matching struct
                if ($this->_pcmlStructs) {
                    // TODO verify type with is_array and count
                    foreach ($this->_pcmlStructs as $possibleStruct) {
                        $possStructAttrs = $possibleStruct->attributes();
                        if ($possStructAttrs['name'] == $structName) {
                            $theStruct = $possibleStruct;
                            $structAttrs = $possStructAttrs;
                            break;
                        }
                    }
                }

                // if struct was not found, generate error for log
                if (!$theStruct) {
//                    $this->getConnection->logThis("PCML structure '$structName' not found.");
                    return null;
                }

                // if we got here, we found our struct.

                // count can also be defined at the structure level. If so, it will override count from data level)
                if (isset($structAttrs['count'])) {
                    $count = (string) $structAttrs['count'];
                }

                // "usage" (in/out/inherit) can be defined here, at the structure level.
                $structUsage = (isset($structAttrs['usage'])) ? (string) $structAttrs['usage'] : '';

                // if we're not inheriting from our parent data element, but there is a struct usage, use the struct's usage (input, output, or inputoutput).
                if (!empty($structUsage) && ($structUsage != 'inherit')) {
                    $usage = $structUsage;
                }

                $structSubDataElementsXmlObj = $theStruct->xpath('data');
                if ($structSubDataElementsXmlObj) {
                    foreach ($structSubDataElementsXmlObj as $subDataElementXmlObj) {

                        if ($subDataElementXmlObj->attributes()->usage == 'inherit') {
                            // subdata is inheriting type from us. Give it to them.
                            $subDataElementXmlObj->attributes()->usage = $usage;
                        }

                        // here's where the recursion comes in. Convert data and add to array for our struct.
                        $subElements[] = $this->singlePcmlToArray($subDataElementXmlObj);
                    }
                }
            }

            $length = (isset($attrs['length'])) ? (string) $attrs['length'] : '';
            $precision = (isset($attrs['precision'])) ? (string) $attrs['precision'] : '';

            //$struct = (isset($attrs['struct'])) ? (string) $attrs['struct'] : ''; // if this is pointing to a struct name

            // find CW data type equivalent of PCML data type
            if (isset($this->_pcmlTypeMap[$type])) {
                // a simple type mapping
                $newType = (string) $this->_pcmlTypeMap[$type];
            } elseif ($type == 'int') {
                // one of the integer types. Need to use length to determine which one.
                if ($length == '2') {
                    $newType = I5_TYPE_SHORT;
                } elseif ($length == '4') {
                    $newType = I5_TYPE_INT;
                } else {
                    $newType = ''; // no match
                }
            } else {
                $newtype = '';

            }

            $newInout = (isset($this->_pcmlInoutMap[$usage])) ? (string) $this->_pcmlInoutMap[$usage] : '';

            // create new length using precision if necessary
            if ($precision) {
                $newLength = "$length.$precision";
            } else {
                $newLength = $length;
            }
        }

        // count
        $newCount = 0; // initialize
        $newCountRef = '';
        if (is_numeric($count) && ($count > 0)) {
            $newCount = $count;
        } elseif (is_string($count) && !empty($count)) {
            // count is character, so it's really a countref
            $newCountRef = $count;
        }

        $element = array();

        $element[$nameName] = $name;

        // if not a struct, provide data type.
        if ($type != 'struct') {
            $element['Type'] = $newType;
        }

        if ($newCount) {
            $element['Count'] = $newCount;
        }
        if ($newCountRef) {
            $element['CountRef'] = $newCountRef;
        }
        if ($newLength) {
            $element['Length'] = $newLength;
        }
        if ($newInout) {
            $element['IO'] = $newInout;
        }

        if (count($subElements)) {
            $element['DSParm'] = $subElements;
        }

        return $element;
    }
909295
private function parseLocationInput (SimpleXMLElement $xml)
    {
        return (new ReflectionClass(Input\Location::class))->newInstanceArgs(
            array_merge(
                $this->getCommonMessageProperties($xml),
                [
                    [(double)$xml->Location_X, (double)$xml->Location_Y],
                    (double)$xml->Scale,
                    (string)$xml->Label,
                ]
            )
        );
    }
1047663
protected function formatKeywordElement(KeywordElement $element)
    {
        $name = $element->getName();
        $keyword = $this->getOption(['keywords', $name]);
        $result = call_user_func($keyword, $element->getValue(), $element, $name);

        if (is_string($result)) {
            $result = ['begin' => $result];
        }

        if (!is_array($result) && !($result instanceof \ArrayAccess)) {
            $this->throwException(
                "The keyword $name returned an invalid value type, string or array was expected.",
                $element
            );
        }

        foreach (['begin', 'end'] as $key) {
            $result[$key] = (isset($result[$key.'Php'])
                ? "<?php\n".$result[$key.'Php']."\n?>"
                : ''
            ).(isset($result[$key])
                ? $result[$key]
                : ''
            );
        }

        return implode('', array_filter([
            $result['begin'],
            $this->formatElementChildren($element),
            $result['end'],
        ]));
    }
463060
public function xml(SimpleXMLElement $parent)
    {
        $option = $parent->addChild('argument');
        $option->addAttribute('name', $this->_name);
        $option->addAttribute('help', $this->_help);
        $option->addAttribute('required', (int)$this->isRequired());
        $choices = $option->addChild('choices');
        foreach ($this->_choices as $valid) {
            $choices->addChild('choice', $valid);
        }

        return $parent;
    }
542188
protected function castValue(SimpleXMLElement $xmlElement)
    {
        $attributes = $xmlElement->attributes();
        if (isset($attributes['nil']) && $attributes['nil'] == 'true') {
            $value = null;
        } else {
            switch (isset($attributes['type']) ? strval($attributes['type']) : null) {
                case 'integer':
                    $value = intval($xmlElement);
                    break;
                case 'float':
                    $value = floatval($xmlElement);
                    break;
                case 'boolean':
                    $value = strval($xmlElement) == 'true';
                    break;
                case 'datetime':
                case 'date':
                    $value = new DateTime(strval($xmlElement));
                    break;
                case 'string':
                default:
                    $value = strval($xmlElement);
                    break;
            }
        }
        return $value;
    }
656052
public function toXmlElement(SimpleXMLElement $parentElement = null)
    {
        if ($parentElement !== null) {
            throw new UserMessageException(t('The sitemap XML header should be the first element.'));
        }

        return new SimpleXMLElement($this->getXmlMetaHeader() . $this->getUrlset(true));
    }
678499
public static function format( $xml, $leadingTabs = FALSE )
	{
		$validator	= new XML_DOM_SyntaxValidator();
		if( !$validator->validate( $xml ) )
			throw new InvalidArgumentException( 'String is no valid XML' ); 

		$document	= new DOMDocument();
		$document->preserveWhiteSpace	= FALSE;
		$document->loadXml( $xml );
		$document->formatOutput = TRUE;
		$xml	= $document->saveXml();

		if( $leadingTabs ){
			$lines	= explode( "\n", $xml );
			foreach( $lines as $nr => $line )
				while( preg_match( "/^\t*  /", $lines[$nr] ) )
					$lines[$nr]	= preg_replace( "/^(\t*)  /", "\\1\t", $lines[$nr] );
			$xml	= implode( "\n", $lines );
		}
		return $xml;
	}
64252
public function parse(
        string $xml,
        string $className = null,
        int $options = null,
        string $ns = null,
        bool $isPrefix = null
    ): \SimpleXMLElement {
        list($content, $error) = $this->softParse($xml, $className, $options, $ns, $isPrefix);
        if ($error !== null) {
            throw $error;
        }
        return $content;
    }
442314
private static function _unserializeRecursive(SimpleXMLElement $xml)
    {
        $result = [];
        $dataNamespace = Resources::DS_XML_NAMESPACE;
        /** @var SimpleXMLElement $child */
        foreach ($xml->children($dataNamespace) as $child) {
            if (count($child->children($dataNamespace)) > 0) {
                $value = [];
                $children = $child->children($dataNamespace);
                /** @var SimpleXMLElement $firstChild */
                $firstChild = $children[0];
                if ($firstChild->getName() == 'element') {
                    foreach ($children as $subChild) {
                        $value[] = self::_unserializeRecursive(
                            $subChild
                        );
                    }
                } else {
                    $value = self::_unserializeRecursive(
                        $child
                    );
                }
            } else {
                $value = (string) $child;
            }

            $result[$child->getName()] = $value;
        }

        return $result;
    }
717501
public function appendChildNode(\SimpleXMLElement $element)
    {
        $target  = dom_import_simplexml($this);
        $insert = $target->ownerDocument->importNode(dom_import_simplexml($element), true);
        $target->appendChild($insert);
    }