• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Utilities/classes/class.ilDOMUtil.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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 //echo "A";
00052                 foreach($childs as $child)
00053                 {
00054                         $child_name = $child->node_name();
00055 //echo "B$child_name";
00056                         if (in_array($child_name, $search))
00057                         {
00058 //echo "C";
00059                                 $found = true;
00060                                 break;
00061                         }
00062                 }
00063                 // didn't find element
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 } // END class.ilDOMUtil
00146 ?>

Generated on Fri Dec 13 2013 17:57:02 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1