diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-20 14:25:47 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-20 14:25:47 +0200 |
commit | 7204e20c725f5d9945596d14f721c5f3191c1283 (patch) | |
tree | 4709023fcf401fbfeb809cb01189f1d3ce3df224 /lib/SimpleSAML/Utils/XML.php | |
parent | c76426b53ffcdb4a254b4aee691792d38bd17a74 (diff) | |
download | simplesamlphp-7204e20c725f5d9945596d14f721c5f3191c1283.zip simplesamlphp-7204e20c725f5d9945596d14f721c5f3191c1283.tar.gz simplesamlphp-7204e20c725f5d9945596d14f721c5f3191c1283.tar.bz2 |
Move SimpleSAML_Utilities::getDOMText() to SimpleSAML\Utils\XML::getDOMText(). Deprecate the former.
Diffstat (limited to 'lib/SimpleSAML/Utils/XML.php')
-rw-r--r-- | lib/SimpleSAML/Utils/XML.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php index d7d488e..0b47ec9 100644 --- a/lib/SimpleSAML/Utils/XML.php +++ b/lib/SimpleSAML/Utils/XML.php @@ -127,4 +127,35 @@ class XML return $doc->saveXML($root); } + + + /** + * This function extracts the text from DOMElements which should contain only text content. + * + * @param \DOMElement $element The element we should extract text from. + * + * @return string The text content of the element. + * @throws \SimpleSAML_Error_Exception If the element contains a non-text child node. + * @author Olav Morken, UNINETT AS <olav.morken@uninett.no> + */ + public static function getDOMText(\DOMElement $element) + { + if (!($element instanceof \DOMElement)) { + throw new \SimpleSAML_Error_Exception('Invalid input parameters'); + } + + $txt = ''; + + for ($i = 0; $i < $element->childNodes->length; $i++) { + $child = $element->childNodes->item($i); + if (!($child instanceof \DOMText)) { + throw new \SimpleSAML_Error_Exception($element->localName.' contained a non-text child node.'); + } + + $txt .= $child->wholeText; + } + + $txt = trim($txt); + return $txt; + } } |