summaryrefslogtreecommitdiffstats
path: root/lib/SAML2
diff options
context:
space:
mode:
authorOlav Morken <olav.morken@uninett.no>2010-04-21 12:55:24 +0000
committerOlav Morken <olav.morken@uninett.no>2010-04-21 12:55:24 +0000
commit712914bea6ca9dda397576540b06d18aeb1cef2b (patch)
tree88281a2b398af69d8a626f762bf5c9a990a46c07 /lib/SAML2
parent7c5b8004711ba667f2613865bb8e4edc2583e163 (diff)
downloadsimplesamlphp-712914bea6ca9dda397576540b06d18aeb1cef2b.zip
simplesamlphp-712914bea6ca9dda397576540b06d18aeb1cef2b.tar.gz
simplesamlphp-712914bea6ca9dda397576540b06d18aeb1cef2b.tar.bz2
SAML2_Utils: add copyElement function.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2256 44740490-163a-0410-bde0-09ae8108e29a
Diffstat (limited to 'lib/SAML2')
-rw-r--r--lib/SAML2/Utils.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/SAML2/Utils.php b/lib/SAML2/Utils.php
index afcd53e..d7cd5c4 100644
--- a/lib/SAML2/Utils.php
+++ b/lib/SAML2/Utils.php
@@ -138,6 +138,50 @@ class SAML2_Utils {
/**
+ * Make an exact copy the specific DOMElement.
+ *
+ * @param DOMElement $element The element we should copy.
+ * @param DOMElement|NULL $parent The target parent element.
+ * @return DOMElement The copied element.
+ */
+ public static function copyElement(DOMElement $element, DOMElement $parent = NULL) {
+
+ if ($parent === NULL) {
+ $document = new DOMDocument();
+ } else {
+ $document = $parent->ownerDocument;
+ }
+
+ $namespaces = array();
+ for ($e = $element; $e !== NULL; $e = $e->parentNode) {
+ foreach (SAML2_Utils::xpQuery($e, './namespace::*') as $ns) {
+ $prefix = $ns->localName;
+ if ($prefix === 'xml' || $prefix === 'xmlns') {
+ continue;
+ }
+ $uri = $ns->nodeValue;
+ if (!isset($namespaces[$prefix])) {
+ $namespaces[$prefix] = $uri;
+ }
+ }
+ }
+
+ $newElement = $document->importNode($element, TRUE);
+ if ($parent !== NULL) {
+ /* We need to append the child to the parent before we add the namespaces. */
+ $parent->appendChild($newElement);
+ }
+
+ foreach ($namespaces as $prefix => $uri) {
+ $newElement->setAttributeNS($uri, $prefix . ':__ns_workaround__', 'tmp');
+ $newElement->removeAttributeNS($uri, '__ns_workaround__');
+ }
+
+ return $newElement;
+ }
+
+
+ /**
* Parse a boolean attribute.
*
* @param DOMElement $node The element we should fetch the attribute from.