(no version information, might be only in CVS)
DomNode_>insert_before __
Inserts new node as child
Description
object
DomNode_>insert_before ( object newnode, object refnode)
This function inserts the new node newnode right
before the node refnode_ The return value is the
inserted node_ If you plan to do further modifications on the appended
child you must use the returned node_
(PHP >= 4_3 only) If newnode already is part of a
document, it will be first unlinked from its existing context_ If
refnode is NULL, then newnode
will be inserted at the end of the list of children_
domnode_insert_before() is very similar to
domnode_append_child() as the following example shows
which does the same as the example at
domnode_append_child()_
Ejemplo 1_ Adding a child <?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>";
?> |
|
See also domnode_append_child()_