PHP Doku:: Adds new sibling to a node - function.domnode-append-sibling.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:

Ein Service von Reinhard Neidl - Webprogrammierung.





(PHP 4 >= 4.2.0)

DomNode->append_sibling Adds new sibling to a node


domelement DomNode->append_sibling ( domelement $newnode )

This functions appends a sibling to an existing node. The child can be created with e.g. domdocument_create_element(), domdocument_create_text() etc. or simply by using any other node.

Before a new sibling is added it is first duplicated. Therefore the new child is a completely new copy which can be modified without changing the node which was passed to this function. If the node passed has children itself, they will be duplicated as well, which makes it quite easy to duplicate large parts of an XML document. The return value is the added sibling. If you plan to do further modifications on the added sibling you must use the returned node.

This function has been added to provide the behaviour of domnode_append_child() as it works till PHP 4.2.

See also domnode_append_before().

Ein BenutzerBeitrag:
- Beiträge aktualisieren...
s dot girard at pandora dot be
1.05.2004 8:06
Small example on the use of domnode->append_sibling()
This function creates a news.xml file, that will be later on parsed with XSLT.

$doc = domxml_new_doc("1.0");
$root = $doc->create_element("rt");
$root = $doc->append_child($root);
$page = $doc->create_element("page");
$page = $root->append_child($page);
while($row = mysql_fetch_row($result))
    $news = $doc->create_element("news");
    $news = $page->append_child($news);
    $topic = $doc->create_element("topic");
    $topic = $news->append_child($topic);
    $topic_content = $doc->create_text_node($row[0]);
    $topic_content = $topic->append_child($topic_content);
    $user = $doc->create_element("user");
    $user = $topic->append_sibling($user);
    $user_content = $doc->create_text_node($row[3]);
    $user_content = $user->append_child($user_content);
    $date = $doc->create_element("date");
    $date = $topic->append_sibling($date);
    $date_content = $doc->create_text_node($row[2]);
    $date_content = $date->append_child($date_content);
    $body = $doc->create_element("body");
    $body = $topic->append_sibling($body);
             $body_content = $doc->create_text_node($row[1]);
    $body_content = $body->append_child($body_content);

PHP Powered Diese Seite bei
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)