Skip to content
Snippets Groups Projects
Commit 9addb1ba authored by Olav Morken's avatar Olav Morken
Browse files

Utilities: Add formatXMLString function, which formats an XML document stored in a string.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@946 44740490-163a-0410-bde0-09ae8108e29a
parent f1a27552
No related branches found
No related tags found
No related merge requests found
...@@ -1625,6 +1625,32 @@ class SimpleSAML_Utilities { ...@@ -1625,6 +1625,32 @@ class SimpleSAML_Utilities {
$root->appendChild(new DOMText("\n" . $indentBase)); $root->appendChild(new DOMText("\n" . $indentBase));
} }
/**
* Format an XML string.
*
* This function formats an XML string using the formatDOMElement function.
*
* @param string $xml XML string which should be formatted.
* @param string $indentBase Optional indentation which should be applied to all
* the output. Optional, defaults to ''.
* @return string Formatted string.
*/
public static function formatXMLString($xml, $indentBase = '') {
assert('is_string($xml)');
assert('is_string($indentBase)');
$doc = new DOMDocument();
if (!$doc->loadXML($xml)) {
throw new Exception('Error parsing XML string.');
}
$root = $doc->firstChild;
self::formatDOMElement($root);
return $doc->saveXML($root);
}
} }
?> ?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment