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
[edit] Last updated: Fri, 10 Feb 2012

view this page in

DomNode::insert_before

(PHP 4 >= 4.1.0)

DomNode::insert_before Insère un nouveau noeud fils

Description

domelement DomNode::insert_before ( domelement $newnode , domelement $refnode )

Cette fonction insère le nouveau noeud fils newnode juste avant le noeud fils refnode. La valeur retournée est la valeur du noeud inséré. Si vous devez faire

(PHP >= 4.3 uniquement) Si newnode fait déjà partie du document, il sera d'abord déconnecté de son contexte courant. Si refnode vaut NULL alors newnode sera inséré à la fin de la liste des fils.

domnode_insert_before() est très similaire à domnode_append_child() comme l'exemple ci-dessous le montre : il réalise la même fonction que l'exemple de domnode_append_child().

Exemple #1 Ajouter un noeud fils

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

if (!
$dom domxml_open_mem($xmlstr)) {
  echo 
"Erreur lors l'analyse du document\n";
  exit;
}

$elements $dom->get_elements_by_tagname("informaltable");
print_r($elements);
$element $elements[0];

$newnode $element->insert_before($element$element);
$children $newnode->children();
$attr $children[1]->set_attribute("align""left");

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

Voir aussi domnode_append_child().



add a note add a note User Contributed Notes DomNode::insert_before
captainbajoo at juno dot com 11-May-2006 02: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