ILIAS  release_8 Revision v8.24
class.ilDOM2Util.php
Go to the documentation of this file.
1<?php
2
25{
26 // change node name
27 public static function changeName(
28 DOMNode $node,
29 string $name,
30 bool $keep_attributes = true
31 ): DOMNode {
32 $newnode = $node->ownerDocument->createElement($name);
33
34 foreach ($node->childNodes as $child) {
35 $child2 = $child->cloneNode(true);
36 $newnode->appendChild($child2);
37 }
38 if ($keep_attributes) {
39 foreach ($node->attributes as $attrName => $attrNode) {
40 $newnode->setAttribute($attrName, $attrNode);
41 }
42 }
43 $node->parentNode->replaceChild($newnode, $node);
44
45 return $newnode;
46 }
47
48 // Add parent
49 public static function addParent(
50 DOMNode $node,
51 string $name
52 ): DOMNode {
53 $newnode = $node->ownerDocument->createElement($name);
54 $par = $node->parentNode;
55 if ($next_sib = $node->nextSibling) {
56 $newnode = $par->insertBefore($newnode, $next_sib);
57 } else {
58 $newnode = $par->appendChild($newnode);
59 }
60
61 $node = $par->removeChild($node);
62 $newnode->appendChild($node);
63 return $newnode;
64 }
65
66 // Replace a node by its child
67 public static function replaceByChilds(DOMNode $node): void
68 {
69 foreach ($node->childNodes as $child) {
70 $child2 = $child->cloneNode(true);
71 $node->parentNode->insertBefore($child2, $node);
72 }
73 $node->parentNode->removeChild($node);
74 }
75}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static changeName(DOMNode $node, string $name, bool $keep_attributes=true)
static replaceByChilds(DOMNode $node)
static addParent(DOMNode $node, string $name)
if($format !==null) $name
Definition: metadata.php:247