From 1503ce8fcd773d19a6beed47fc8dfb0c1d3c6b26 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 21 Feb 2008 12:16:01 +0000
Subject: [PATCH] Utilities: Added getDOMChildren function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@318 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index ddf3d7953..7762f9f9b 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -508,6 +508,41 @@ class SimpleSAML_Utilities {
 
 		return TRUE;
 	}
+
+
+	/**
+	 * 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 $element The element we should look in.
+	 * @param $localName The name the element should have.
+	 * @param $namespaceURI The namespace the element should have.
+	 * @return Array with the matching elements in the order they are found. An empty array is
+	 *         returned if no elements match.
+	 */
+	public static function getDOMChildren($element, $localName, $namespaceURI) {
+		assert('$element instanceof DOMElement');
+
+		$ret = array();
+
+		for($i = 0; $i < $element->childNodes->length; $i++) {
+			$child = $element->childNodes->item($i);
+
+			/* Skip text nodes. */
+			if($child instanceof DOMText) {
+				continue;
+			}
+
+			if(self::isDOMElementOfType($child, $localName, $namespaceURI) === TRUE) {
+				$ret[] = $child;
+			}
+		}
+
+		return $ret;
+	}
+
 }
 
 ?>
\ No newline at end of file
-- 
GitLab