diff options
author | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-20 14:48:22 +0200 |
---|---|---|
committer | Jaime Perez Crespo <jaime.perez@uninett.no> | 2015-04-20 14:48:22 +0200 |
commit | 3cc3abdb78630899f80606675580af0c30ffedb9 (patch) | |
tree | fa35edded28d0a99a030840a2c118acf3c25a1da /lib/SimpleSAML/Utils/XML.php | |
parent | 20a0b6c93923b83a401d7f98af0305162acd0a35 (diff) | |
download | simplesamlphp-3cc3abdb78630899f80606675580af0c30ffedb9.zip simplesamlphp-3cc3abdb78630899f80606675580af0c30ffedb9.tar.gz simplesamlphp-3cc3abdb78630899f80606675580af0c30ffedb9.tar.bz2 |
Move SimpleSAML_Utilities::getDOMChildren() to SimpleSAML\Utils\XML::getDOMChildren(). Deprecate the former.
Diffstat (limited to 'lib/SimpleSAML/Utils/XML.php')
-rw-r--r-- | lib/SimpleSAML/Utils/XML.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/SimpleSAML/Utils/XML.php b/lib/SimpleSAML/Utils/XML.php index 5a2b3da..e18d7ff 100644 --- a/lib/SimpleSAML/Utils/XML.php +++ b/lib/SimpleSAML/Utils/XML.php @@ -131,6 +131,43 @@ class XML /** + * This function finds direct descendants of a DOM element with the specified + * localName and namespace. They are returned in an array. + * + * This function accepts the same shortcuts for namespaces as the isDOMElementOfType function. + * + * @param \DOMElement $element The element we should look in. + * @param string $localName The name the element should have. + * @param string $namespaceURI The namespace the element should have. + * + * @return array Array with the matching elements in the order they are found. An empty array is + * returned if no elements match. + */ + public static function getDOMChildren(\DOMElement $element, $localName, $namespaceURI) + { + assert('is_string($localName)'); + assert('is_string($namespaceURI)'); + + $ret = array(); + + for ($i = 0; $i < $element->childNodes->length; $i++) { + $child = $element->childNodes->item($i); + + // skip text nodes and comment elements + if ($child instanceof \DOMText || $child instanceof \DOMComment) { + continue; + } + + if (self::isDOMElementOfType($child, $localName, $namespaceURI) === true) { + $ret[] = $child; + } + } + + return $ret; + } + + + /** * This function extracts the text from DOMElements which should contain only text content. * * @param \DOMElement $element The element we should extract text from. |