From 9addb1ba594c13f4eeb832b9a331e25dc7cc1890 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Mon, 27 Oct 2008 13:18:12 +0000 Subject: [PATCH] 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 --- lib/SimpleSAML/Utilities.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php index beada9913..8e121d7cf 100644 --- a/lib/SimpleSAML/Utilities.php +++ b/lib/SimpleSAML/Utilities.php @@ -1625,6 +1625,32 @@ class SimpleSAML_Utilities { $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 -- GitLab