Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00033 class ilDOMUtil
00034 {
00035
00042 function setFirstOptionalElement(&$doc, &$parent_node, $a_node_name, $a_successors,
00043 $a_content, $a_attributes, $a_remove_childs = true)
00044 {
00045 $search = $a_successors;
00046 $search[] = $a_node_name;
00047
00048 $childs = $parent_node->child_nodes();
00049 $cnt_childs = count($childs);
00050 $found = false;
00051
00052 foreach($childs as $child)
00053 {
00054 $child_name = $child->node_name();
00055
00056 if (in_array($child_name, $search))
00057 {
00058
00059 $found = true;
00060 break;
00061 }
00062 }
00063
00064 if(!$found)
00065 {
00066 $new_node =& $doc->create_element($a_node_name);
00067 $new_node =& $parent_node->append_child($new_node);
00068 if ($a_content != "")
00069 {
00070 $new_node->set_content($a_content);
00071 }
00072 ilDOMUtil::set_attributes($new_node, $a_attributes);
00073 }
00074 else
00075 {
00076 if ($child_name == $a_node_name)
00077 {
00078 if ($a_remove_childs)
00079 {
00080 $childs2 = $child->child_nodes();
00081 for($i=0; $i<count($childs2); $i++)
00082 {
00083 $child->remove_child($childs2[$i]);
00084 }
00085 }
00086 if ($a_content != "")
00087 {
00088 $child->set_content($a_content);
00089 }
00090 ilDOMUtil::set_attributes($child, $a_attributes);
00091 }
00092 else
00093 {
00094 $new_node =& $doc->create_element($a_node_name);
00095 $new_node =& $child->insert_before($new_node, $child);
00096 if ($a_content != "")
00097 {
00098 $new_node->set_content($a_content);
00099 }
00100 ilDOMUtil::set_attributes($new_node, $a_attributes);
00101 }
00102 }
00103 }
00104
00111 function set_attributes(&$a_node, $a_attributes)
00112 {
00113 foreach ($a_attributes as $attribute => $value)
00114 {
00115 if ($value != "")
00116 {
00117 $a_node->set_attribute($attribute, $value);
00118 }
00119 else
00120 {
00121 if ($a_node->has_attribute($attibute))
00122 {
00123 $a_node->remove_attribute($attribute);
00124 }
00125 }
00126 }
00127 }
00128
00132 function deleteAllChildsByName(&$a_parent, $a_node_names)
00133 {
00134 $childs = $a_parent->child_nodes();
00135 foreach($childs as $child)
00136 {
00137 $child_name = $child->node_name();
00138 if (in_array($child_name, $a_node_names))
00139 {
00140 $child->unlink_node();
00141 }
00142 }
00143 }
00144
00145 }
00146 ?>