ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDOM2Util.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
20 public static function changeName($node, $name, $keep_attributes = true)
21 {
22 $newnode = $node->ownerDocument->createElement($name);
23
24 foreach ($node->childNodes as $child) {
25 $child2 = $child->cloneNode(true);
26 $newnode->appendChild($child2);
27 }
28 if ($keep_attributes) {
29 foreach ($node->attributes as $attrName => $attrNode) {
30 $newnode->setAttribute($attrName, $attrNode);
31 }
32 }
33 $node->parentNode->replaceChild($newnode, $node);
34
35 return $newnode;
36 }
37
44 public static function addParent($node, $name)
45 {
46 $newnode = $node->ownerDocument->createElement($name);
47 //echo htmlentities($node->ownerDocument->saveXML($node->ownerDocument->documentElement));
48 //echo "<br>".htmlentities($node->ownerDocument->saveXML($node)); exit;
49 $par = $node->parentNode;
50 //var_dump($node);
51 //var_dump($par);
52 if ($next_sib = $node->nextSibling) {
53 $newnode = $par->insertBefore($newnode, $next_sib);
54 } else {
55 $newnode = $par->appendChild($newnode);
56 }
57
58 $node = $par->removeChild($node);
59 $newnode->appendChild($node);
60
61 // foreach ($node->childNodes as $child)
62 // {
63 // $child2 = $child->cloneNode(true);
64 // $newnode->appendChild($child2);
65 // }
66
67 return $newnode;
68 }
69
76 public static function replaceByChilds($node)
77 {
78 foreach ($node->childNodes as $child) {
79 $child2 = $child->cloneNode(true);
80 $node->parentNode->insertBefore($child2, $node);
81 }
82 $node->parentNode->removeChild($node);
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
DOM 2 util.
static addParent($node, $name)
Add parent.
static replaceByChilds($node)
Replace a node by its child.
static changeName($node, $name, $keep_attributes=true)
Change name of a node.
if($format !==null) $name
Definition: metadata.php:146