ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  static function changeName($node, $name, $keep_attributes = true)
21  {
22  $newnode = $node->ownerDocument->createElement($name);
23 
24  foreach ($node->childNodes as $child)
25  {
26  $child2 = $child->cloneNode(true);
27  $newnode->appendChild($child2);
28  }
29  if ($keep_attributes)
30  {
31  foreach ($node->attributes as $attrName => $attrNode)
32  {
33  $newnode->setAttribute($attrName, $attrNode);
34  }
35  }
36  $node->parentNode->replaceChild($newnode, $node);
37 
38  return $newnode;
39  }
40 
47  static function addParent($node, $name)
48  {
49  $newnode = $node->ownerDocument->createElement($name);
50 //echo htmlentities($node->ownerDocument->saveXML($node->ownerDocument->documentElement));
51 //echo "<br>".htmlentities($node->ownerDocument->saveXML($node)); exit;
52  $par = $node->parentNode;
53 //var_dump($node);
54 //var_dump($par);
55  if ($next_sib = $node->nextSibling)
56  {
57  $newnode = $par->insertBefore($newnode, $next_sib);
58  }
59  else
60  {
61  $newnode = $par->appendChild($newnode);
62  }
63 
64  $node = $par->removeChild($node);
65  $newnode->appendChild($node);
66 
67 // foreach ($node->childNodes as $child)
68 // {
69 // $child2 = $child->cloneNode(true);
70 // $newnode->appendChild($child2);
71 // }
72 
73  return $newnode;
74  }
75 
82  static function replaceByChilds($node)
83  {
84  foreach ($node->childNodes as $child)
85  {
86  $child2 = $child->cloneNode(true);
87  $node->parentNode->insertBefore($child2, $node);
88  }
89  $node->parentNode->removeChild($node);
90  }
91 
92 }
93 ?>