PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DomNode->replace_child> <DomNode->previous_sibling
Last updated: Fri, 22 Aug 2008

view this page in

DomNode->remove_child

(No version information available, might be only in CVS)

DomNode->remove_child Elimina un hijo de una lista de hijos

Descripción

domtext DomNode->remove_child ( domtext $hijo_antiguo )

Esta función elimina un hijo de una lista de hijos. Si el hijo no puede ser eliminado, o no es un hijo, la función devuelve FALSE. Si el hijo puede ser eliminado, la función devuelve el hijo antiguo.

Example #1 Eliminar un hijo

<?php
include("ejemplo.inc");

if (!
$dom domxml_open_mem($cadena_xml)) {
  echo 
"Ocurri&oacute; un error al analizar el documento\n";
  exit;
}

$elementos $dom->get_elements_by_tagname("tbody");
$elemento $elementos[0];
$hijos $elemento->child_nodes();
$hijo $elemento->remove_child($hijos[0]);

echo 
"<PRE>";
$archivo_xml $dom->dump_mem(true);
echo 
htmlentities($archivo_xml);
echo 
"</PRE>";
?>

Vea también domnode_append_child().



add a note add a note User Contributed Notes
DomNode->remove_child
iloveitaly at gmail.com
05-Dec-2004 03:28
The remove_child() function seems to have a bug. if the parent node  of the node you are trying to delete is the same as the root node it will give you unexpected errors. I fixed this by checking if the parent node of the node i was deleting was the same as the document node. take a look at the function below if you are running into the same problem. $this->xmlData reffers to the domxml object inside the class i was using.
<?php
   
function deleteNode($ref, $levels) {
       
$parent = $ref->parent_node();
       
$root = $this->xmlData->document_element();
        if(
$parent->node_name()==$root->node_name()) {
           
$parent = $this->xmlData->document_element();
        }
        if(
$parent->remove_child($ref)) {
            return
true;
        } else {
            exit(
"error removing node");
        }
    }
?>

DomNode->replace_child> <DomNode->previous_sibling
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites