summaryrefslogtreecommitdiffstats
path: root/lib/SimpleSAML/Utils/XML.php
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2015-04-20 13:48:23 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2015-04-20 13:48:23 +0200
commit44818e229d01b6d58a0e13c807b6da9862013407 (patch)
tree585828253a5f00ad2d7c656b45489426c4717fd1 /lib/SimpleSAML/Utils/XML.php
parent7827bfc5a37695a51d907f542fd8b5ac6dc61d93 (diff)
downloadsimplesamlphp-44818e229d01b6d58a0e13c807b6da9862013407.zip
simplesamlphp-44818e229d01b6d58a0e13c807b6da9862013407.tar.gz
simplesamlphp-44818e229d01b6d58a0e13c807b6da9862013407.tar.bz2
Move SimpleSAML_Utilities::formatXMLString() to SimpleSAML\Utils\XML::formatXMLString(). Deprecate the former.
Diffstat (limited to 'lib/SimpleSAML/Utils/XML.php')
-rw-r--r--lib/SimpleSAML/Utils/XML.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php
index faec37b..1aee763 100644
--- a/lib/SimpleSAML/Utils/XML.php
+++ b/lib/SimpleSAML/Utils/XML.php
@@ -93,4 +93,35 @@ class XML
// add indentation before closing tag
$root->appendChild(new DOMText("\n".$indentBase));
}
+
+ /**
+ * Format an XML string.
+ *
+ * This function formats an XML string using the formatDOMElement() function.
+ *
+ * @param string $xml An XML string which should be formatted.
+ * @param string $indentBase Optional indentation which should be applied to all the output. Optional, defaults
+ * to ''.
+ *
+ * @return string The formatted string.
+ *
+ * @throws SimpleSAML_Error_Exception If the input does not parse correctly as an XML string.
+ *
+ * @author Olav Morken, UNINETT AS <olav.morken@uninett.no>
+ */
+ public static function formatXMLString($xml, $indentBase = '')
+ {
+ assert('is_string($xml)');
+ assert('is_string($indentBase)');
+
+ $doc = new DOMDocument();
+ if (!$doc->loadXML($xml)) {
+ throw new SimpleSAML_Error_Exception('Error parsing XML string.');
+ }
+
+ $root = $doc->firstChild;
+ self::formatDOMElement($root, $indentBase);
+
+ return $doc->saveXML($root);
+ }
}