Public Member Functions

ilDOMUtil Class Reference

Public Member Functions

 setFirstOptionalElement (&$doc, &$parent_node, $a_node_name, $a_successors, $a_content, $a_attributes, $a_remove_childs=true)
 searches for an element $a_node_name within the childs of $parent_node if no node is found, a new is created before the childs with names of $a_successors.
 set_attributes (&$a_node, $a_attributes)
 set attributes of a node
 deleteAllChildsByName (&$a_parent, $a_node_names)
 delete all childs of a node by names in $a_node_names

Detailed Description

Definition at line 32 of file class.ilDOMUtil.php.


Member Function Documentation

ilDOMUtil::deleteAllChildsByName ( &$  a_parent,
a_node_names 
)

delete all childs of a node by names in $a_node_names

Definition at line 131 of file class.ilDOMUtil.php.

Referenced by ilPCTable::setCaption().

        {
                $childs = $a_parent->child_nodes();
                foreach($childs as $child)
                {
                        $child_name = $child->node_name();
                        if (in_array($child_name, $a_node_names))
                        {
                                $child->unlink_node();
                        }
                }
        }

Here is the caller graph for this function:

ilDOMUtil::set_attributes ( &$  a_node,
a_attributes 
)

set attributes of a node

Parameters:
object $a_node node
array $a_attributes attributes array (attribute_name => attribute_value pairs)

Definition at line 110 of file class.ilDOMUtil.php.

Referenced by setFirstOptionalElement().

        {
                foreach ($a_attributes as $attribute => $value)
                {
                        if ($value != "")
                        {
                                $a_node->set_attribute($attribute, $value);
                        }
                        else
                        {
                                if ($a_node->has_attribute($attibute))
                                {
                                        $a_node->remove_attribute($attribute);
                                }
                        }
                }
        }

Here is the caller graph for this function:

ilDOMUtil::setFirstOptionalElement ( &$  doc,
&$  parent_node,
a_node_name,
a_successors,
a_content,
a_attributes,
a_remove_childs = true 
)

searches for an element $a_node_name within the childs of $parent_node if no node is found, a new is created before the childs with names of $a_successors.

the content of the node is set to $a_content and the attributes to $a_attributes

Definition at line 41 of file class.ilDOMUtil.php.

References set_attributes().

Referenced by ilPCTable::setCaption(), ilMediaAliasItem::setCaption(), ilMediaAliasItem::setHeight(), ilMediaAliasItem::setHorizontalAlign(), ilPCFileList::setListTitle(), and ilMediaAliasItem::setWidth().

        {
                $search = $a_successors;
                $search[] = $a_node_name;

                $childs = $parent_node->child_nodes();
                $cnt_childs = count($childs);
                $found = false;
//echo "A";
                foreach($childs as $child)
                {
                        $child_name = $child->node_name();
//echo "B$child_name";
                        if (in_array($child_name, $search))
                        {
//echo "C";
                                $found = true;
                                break;
                        }
                }
                // didn't find element
                if(!$found)
                {
                        $new_node =& $doc->create_element($a_node_name);
                        $new_node =& $parent_node->append_child($new_node);
                        if ($a_content != "")
                        {
                                $new_node->set_content($a_content);
                        }
                        ilDOMUtil::set_attributes($new_node, $a_attributes);
                }
                else
                {
                        if ($child_name == $a_node_name)
                        {
                                if ($a_remove_childs)
                                {
                                        $childs2 = $child->child_nodes();
                                        for($i=0; $i<count($childs2); $i++)
                                        {
                                                $child->remove_child($childs2[$i]);
                                        }
                                }
                                if ($a_content != "")
                                {
                                        $child->set_content($a_content);
                                }
                                ilDOMUtil::set_attributes($child, $a_attributes);
                        }
                        else
                        {
                                $new_node =& $doc->create_element($a_node_name);
                                $new_node =& $child->insert_before($new_node, $child);
                                if ($a_content != "")
                                {
                                        $new_node->set_content($a_content);
                                }
                                ilDOMUtil::set_attributes($new_node, $a_attributes);
                        }
                }
        }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: