protected function pretty()
    {
        $xml = $this->getParameter('value');
        $level = $this->getParameter('level') != null ? intval($this->getParameter('level')) : 6;

        // get an array containing each XML element
        $xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml));

        // hold current indentation level
        $indent = 0;

        // hold the XML segments
        $pretty = array();

        // shift off opening XML tag if present
        if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
            $pretty[] = array_shift($xml);
        }

        foreach ($xml as $el) {
            if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
                if($indent < 0) $indent = 0;
                // opening tag, increase indent
                $pretty[] = str_repeat('&nbsp;', $indent) . htmlentities($el,ENT_QUOTES);
                $indent += $level;
            } else {
                if (preg_match('/^<\/.+>$/', $el)) {
                    // closing tag, decrease indent
                    $indent -= $level;
                }
                $pretty[] = str_repeat('&nbsp;', abs($indent)) . htmlentities($el,ENT_QUOTES);
            }
        }

        return implode("<br/>", $pretty);
    }
protected function pretty()
    {
        $xml = $this->getParameter('value');
        $level = $this->getParameter('level') != null ? intval($this->getParameter('level')) : 6;

        // get an array containing each XML element
        $xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml));

        // hold current indentation level
        $indent = 0;

        // hold the XML segments
        $pretty = array();

        // shift off opening XML tag if present
        if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
            $pretty[] = array_shift($xml);
        }

        foreach ($xml as $el) {
            if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
                if($indent < 0) $indent = 0;
                // opening tag, increase indent
                $pretty[] = str_repeat('&nbsp;', $indent) . htmlentities($el,ENT_QUOTES);
                $indent += $level;
            } else {
                if (preg_match('/^<\/.+>$/', $el)) {
                    // closing tag, decrease indent
                    $indent -= $level;
                }
                $pretty[] = str_repeat('&nbsp;', abs($indent)) . htmlentities($el,ENT_QUOTES);
            }
        }

        return implode("<br/>", $pretty);
    }
protected function pretty ( ) { $ xml = $ this -> getParameter ( 'value' ) ; $ level = $ this -> getParameter ( 'level' ) != null ? intval ( $ this -> getParameter ( 'level' ) ) : 6 ; // get an array containing each XML element $ xml = explode ( "\n" , preg_replace ( '/>\s*</' , ">\n<" , $ xml ) ) ; // hold current indentation level $ indent = 0 ; // hold the XML segments $ pretty = array ( ) ; // shift off opening XML tag if present if ( count ( $ xml ) && preg_match ( '/^<\?\s*xml/' , $ xml [ 0 ] ) ) { $ pretty [ ] = array_shift ( $ xml ) ; } foreach ( $ xml as $ el ) { if ( preg_match ( '/^<([\w])+[^>\/]*>$/U' , $ el ) ) { if ( $ indent < 0 ) $ indent = 0 ; // opening tag, increase indent $ pretty [ ] = str_repeat ( '&nbsp;' , $ indent ) . htmlentities ( $ el , ENT_QUOTES ) ; $ indent += $ level ; } else { if ( preg_match ( '/^<\/.+>$/' , $ el ) ) { // closing tag, decrease indent $ indent -= $ level ; } $ pretty [ ] = str_repeat ( '&nbsp;' , abs ( $ indent ) ) . htmlentities ( $ el , ENT_QUOTES ) ; } } return implode ( "<br/>" , $ pretty ) ; }
Formats an XML string

Expected Param:
value string XML snippet

@return string
Formats an XML string