ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilDOMUtil Class Reference

class for DOM utilities More...

+ Collaboration diagram for ilDOMUtil:

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
 addElementToList (&$doc, &$parent_node, $a_node_name, $a_successors, $a_content, $a_attributes)
 Places a new node $a_node_name directly before nodes with names of $a_successors.

Detailed Description

class for DOM utilities

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilDOMUtil.php 17101 2008-08-03 10:30:43Z akill

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

Member Function Documentation

ilDOMUtil::addElementToList ( $doc,
$parent_node,
  $a_node_name,
  $a_successors,
  $a_content,
  $a_attributes 
)

Places a new node $a_node_name directly before nodes with names of $a_successors.

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

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

References set_attributes().

Referenced by ilMediaAliasItem\addMapArea(), ilPCInteractiveImage\addTriggerArea(), ilPCInteractiveImage\addTriggerMarker(), and ilMediaAliasItem\setParameters().

{
$search = $a_successors;
$childs = $parent_node->child_nodes();
$cnt_childs = count($childs);
$found = false;
foreach($childs as $child)
{
$child_name = $child->node_name();
if (in_array($child_name, $search))
{
$found = true;
break;
}
}
// didn't successors -> append at the end
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
{
$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);
}
return $new_node;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilDOMUtil::deleteAllChildsByName ( $a_parent,
  $a_node_names 
)

delete all childs of a node by names in $a_node_names

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

Referenced by ilPCTabs\saveCaptions(), ilMediaAliasItem\setAreaExtLink(), ilMediaAliasItem\setAreaIntLink(), and 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_nodenode
array$a_attributesattributes array (attribute_name => attribute_value pairs)

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

Referenced by addElementToList(), and 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 42 of file class.ilDOMUtil.php.

References set_attributes().

Referenced by ilMediaAliasItem\addMapArea(), ilPCTabs\addTab(), ilPCTabs\saveCaptions(), ilMediaAliasItem\setAreaExtLink(), ilMediaAliasItem\setAreaIntLink(), ilMediaAliasItem\setCaption(), ilPCTable\setCaption(), ilMediaAliasItem\setHeight(), ilMediaAliasItem\setHorizontalAlign(), ilPCFileList\setListTitle(), ilMediaAliasItem\setTextRepresentation(), 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: