SimpleSAML\Utils\XML::getDOMText PHP Method

getDOMText() public static method

This function extracts the text from DOMElements which should contain only text content.
Author: Olav Morken, UNINETT AS ([email protected])
public static getDOMText ( DOMElement $element ) : string
$element DOMElement The element we should extract text from.
return string The text content of the element.
    public static function getDOMText(\DOMElement $element)
    {
        if (!$element instanceof \DOMElement) {
            throw new \InvalidArgumentException('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;
    }