Revision: 2256
Author: olavmrk
Date: Wed Apr 21 05:55:24 2010
Log: SAML2_Utils: add copyElement function.
http://code.google.com/p/simplesamlphp/source/detail?r=2256
Modified:
/trunk/lib/SAML2/Utils.php
=======================================
--- /trunk/lib/SAML2/Utils.php Tue Apr 20 04:59:24 2010
+++ /trunk/lib/SAML2/Utils.php Wed Apr 21 05:55:24 2010
@@ -135,6 +135,50 @@
return $ret;
}
+
+
+ /**
+ * 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;
+ }
/**
--
You received this message because you are subscribed to the Google Groups
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/simplesamlphp-commits?hl=en.