public static function getFormattedDocument($xml)
    {
        $oldValue = $xml->preserveWhiteSpace;
        $oldFormatOutput = $xml->formatOutput;

        $xml->preserveWhiteSpace = false;
        $xml->formatOutput = true;
        $document = $xml->saveXML();

        $xml->preserveWhiteSpace = $oldValue;
        $xml->formatOutput = $oldFormatOutput;

        return $document;
    }