/** * @param string $name * @param string $ns * @param bool $native * * @return $this|Element|Tag|Field */ public function rename($name, $ns = '', $native = false) { if (!empty($name)) { if ($native) { /** not implement yet */ $this->ownerDocument->renameNode($this, $ns, $name); return $this; } $name = (string) $name; $old = $this->copy(); $new = $this->ownerDocument->createElement($name); $new->attr($old->attributes()); $children = $old->children(); foreach ($children as $child) { $new->append($child); } $this->parent()->replaceChild($new, $this); return $new; } return $this; }