PHP
downloads | documentation | faq | getting help | mailing lists | 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, 03 Oct 2008

view this page in

DomNode->insert_before

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

DomNode->insert_before 新規ノードを子ノードとして挿入する

説明

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

この関数は新規ノード newnode をノード refnode の直前に挿入します。 戻り値は挿入されたノードです。 もし追加された子ノードを変更するつもりであれば、 返されたノードを使用する必要があります。

(PHP >= 4.3 のみ) newnode がすでに文章の一部である場合、最初に既存のコンテキストから削除されます。 もし refnode が NULL の場合、 newnode は子ノードリストの最後に挿入されます。

domnode_insert_before()domnode_append_child() に非常に似ており、 以下の例は domnode_append_child() にある例と同様のことを行うことを示しています。

例1 子ノードを追加する

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

if (!
$dom domxml_open_mem($xmlstr)) {
  echo 
"Error while parsing the 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>";
?>

domnode_append_child() も参照ください。



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

DomNode->is_blank_node> <DomNode->has_child_nodes
Last updated: Fri, 03 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites