src/Type/Xml.php
public static function encode($data, $prettyPrint = false, $xmlVersion = '1.0', $encoding = 'utf-8')
    {
        $domDocument = new DOMDocument($xmlVersion, $encoding);
        $domDocument = self::loopEncode($data, $domDocument);
        
        if ($prettyPrint) {
            $domDocument->preserveWhiteSpace = false;
            $domDocument->formatOutput = true;
        }

        $resultString = $domDocument->saveXML();

        if (!$prettyPrint) {
            $resultStringLines = explode(PHP_EOL, $resultString);
            $documentLine = array_shift($resultStringLines);

            $resultString = $documentLine . PHP_EOL . implode('', $resultStringLines);
        } else {
            $resultString = trim($resultString, PHP_EOL);
        }

        return $resultString;
    }
public static function encode($data, $prettyPrint = false, $xmlVersion = '1.0', $encoding = 'utf-8')
    {
        $domDocument = new DOMDocument($xmlVersion, $encoding);
        $domDocument = self::loopEncode($data, $domDocument);
        
        if ($prettyPrint) {
            $domDocument->preserveWhiteSpace = false;
            $domDocument->formatOutput = true;
        }

        $resultString = $domDocument->saveXML();

        if (!$prettyPrint) {
            $resultStringLines = explode(PHP_EOL, $resultString);
            $documentLine = array_shift($resultStringLines);

            $resultString = $documentLine . PHP_EOL . implode('', $resultStringLines);
        } else {
            $resultString = trim($resultString, PHP_EOL);
        }

        return $resultString;
    }
public static function encode ( $ data , $ prettyPrint = false , $ xmlVersion = '1.0' , $ encoding = 'utf-8' ) { $ domDocument = new DOMDocument ( $ xmlVersion , $ encoding ) ; $ domDocument = self :: loopEncode ( $ data , $ domDocument ) ; if ( $ prettyPrint ) { $ domDocument -> preserveWhiteSpace = false ; $ domDocument -> formatOutput = true ; } $ resultString = $ domDocument -> saveXML ( ) ; if ( ! $ prettyPrint ) { $ resultStringLines = explode ( PHP_EOL , $ resultString ) ; $ documentLine = array_shift ( $ resultStringLines ) ; $ resultString = $ documentLine . PHP_EOL . implode ( '' , $ resultStringLines ) ; } else { $ resultString = trim ( $ resultString , PHP_EOL ) ; } return $ resultString ; }
Encodes an array to xml strutcture
@param  mixed   $data        Data to encode
@param  boolean $prettyPrint True to output the encoded data a little bit more readable for the humans
@param  string  $xmlVersion  XML header version
@param  string  $encoding    XML header encoding
@return string
Encodes an array to xml strutcture