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

search for in the

DomNode->is_blank_node> <DomNode->has_child_nodes
Last updated: Fri, 20 May 2011

view this page in

DomNode->insert_before

(PHP 4 >= 4.1.0)

DomNode->insert_before Inserta un nodo nuevo como hijo

Descripción

domelement DomNode->insert_before ( domelement $newnode , domelement $refnode )

Esta función inserta el nuevo nodo, nodo_nuevo, justo antes del nodo nodo_ref. El valor de retorno es el nodo insertado. Si planea hacer modificaciones posteriores sobre el hijo agregado, debe usar el nodo devuelto.

(Solo PHP >= 4.3) Si nodo_nuevo ya es parte de un documento, será primero desenlazado de su contexto actual. Si nodo_ref es NULL, entonces nodo_nuevo será insertado al final de la lista de hijos.

domnode_insert_before() es bastante similar a domnode_append_child() como muestra el siguiente ejemplo, el cual hace lo mismo que el ejemplo en domnode_append_child().

Example #1 Agregar 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("informaltable");
print_r($elementos);
$elemento $elementos[0];

$nodo_nuevo $elemento->insert_before($elemento$elemento);
$hijos $nodo_nuevo->children();
$atr $hijos[1]->set_attribute("align""left");

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

Vea también domnode_append_child().



add a note add a note User Contributed Notes DomNode->insert_before
captainbajoo at juno dot com 11-May-2006 03:40
In a numbered ordering of the document's nodes, insertBefore() will place newNode at the index held by refNode, and increment refNode's index and all subsequent nodes' indices. This is instead of maintaining refNode's index, placing newNode at refNode's position minus one, and shifting all previous nodes' indices down by one.

The base case of refNode.index = 0 demonstrates why this must be the case, but it is good to know this explicitly, as it affects methods that deal with iteration such as getElementsByTagName().

 
show source | credits | stats | sitemap | contact | advertising | mirror sites