/** * @param \DOMElement $node * @param \stdClass $data */ protected function transferNamespacesTo(\DOMElement $node, $data) { foreach ($data as $key => $namespace) { $prefix = $key === '$' ? NULL : $key; if ($node->lookupNamespaceUri($prefix) != $namespace) { $node->setAttribute(empty($prefix) ? 'xmlns' : 'xmlns:' . $prefix, $namespace); } } }
/** * @param \DOMElement $node * @param \stdClass $properties */ private function addNamespaceAttributes(\DOMElement $node, $properties) { foreach ($properties as $name => $value) { if ($name === 'xmlns' || substr($name, 0, 6) === 'xmlns:') { if ($node instanceof \DOMElement) { $prefix = $name === 'xmlns' ? NULL : substr($name, 6); if ($node->lookupNamespaceUri($prefix) != $value) { $node->setAttribute($name, $value); } } } } }
/** * @param \DOMElement $element * @param string $text * @return NamespaceName */ public static function create(\DOMElement $element, $text) { list($prefix, $name) = explode(':', $text); $namespace = $element->lookupNamespaceUri($prefix); return new NamespaceName($namespace, $name); }