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
00032 class ilDOMUtil
00033 {
00034
00041 function setFirstOptionalElement(&$doc, &$parent_node, $a_node_name, $a_successors,
00042 $a_content, $a_attributes, $a_remove_childs = true)
00043 {
00044 $search = $a_successors;
00045 $search[] = $a_node_name;
00046
00047 $childs = $parent_node->child_nodes();
00048 $cnt_childs = count($childs);
00049 $found = false;
00050
00051 foreach($childs as $child)
00052 {
00053 $child_name = $child->node_name();
00054
00055 if (in_array($child_name, $search))
00056 {
00057
00058 $found = true;
00059 break;
00060 }
00061 }
00062
00063 if(!$found)
00064 {
00065 $new_node =& $doc->create_element($a_node_name);
00066 $new_node =& $parent_node->append_child($new_node);
00067 if ($a_content != "")
00068 {
00069 $new_node->set_content($a_content);
00070 }
00071 ilDOMUtil::set_attributes($new_node, $a_attributes);
00072 }
00073 else
00074 {
00075 if ($child_name == $a_node_name)
00076 {
00077 if ($a_remove_childs)
00078 {
00079 $childs2 = $child->child_nodes();
00080 for($i=0; $i<count($childs2); $i++)
00081 {
00082 $child->remove_child($childs2[$i]);
00083 }
00084 }
00085 if ($a_content != "")
00086 {
00087 $child->set_content($a_content);
00088 }
00089 ilDOMUtil::set_attributes($child, $a_attributes);
00090 }
00091 else
00092 {
00093 $new_node =& $doc->create_element($a_node_name);
00094 $new_node =& $child->insert_before($new_node, $child);
00095 if ($a_content != "")
00096 {
00097 $new_node->set_content($a_content);
00098 }
00099 ilDOMUtil::set_attributes($new_node, $a_attributes);
00100 }
00101 }
00102 }
00103
00110 function set_attributes(&$a_node, $a_attributes)
00111 {
00112 foreach ($a_attributes as $attribute => $value)
00113 {
00114 if ($value != "")
00115 {
00116 $a_node->set_attribute($attribute, $value);
00117 }
00118 else
00119 {
00120 if ($a_node->has_attribute($attibute))
00121 {
00122 $a_node->remove_attribute($attribute);
00123 }
00124 }
00125 }
00126 }
00127
00131 function deleteAllChildsByName(&$a_parent, $a_node_names)
00132 {
00133 $childs = $a_parent->child_nodes();
00134 foreach($childs as $child)
00135 {
00136 $child_name = $child->node_name();
00137 if (in_array($child_name, $a_node_names))
00138 {
00139 $child->unlink_node();
00140 }
00141 }
00142 }
00143
00144 }
00145 ?>