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

search for in the

DomNode->attributes> <DomNode->append_child
Last updated: Fri, 27 Jun 2008

view this page in

DomNode->append_sibling

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

DomNode->append_sibling — Aggiunge un nodo fratello

Descrizione

object DomNode->append_sibling ( object $nuovo_nodo )

Questa funzione aggiunge un nodo di pari livello rispetto ad un nodo esistente. Il nodo figlio può essere creato con funzioni del tipo domdocument_create_element(), domdocument_create_text() ecc. oppure utilizzando un'altro nodo.

Prima dell'aggiunta come nuovo nodo fratello, il nodo viene duplicato. Quindi il nuovo nodo figlio è una nuova copia dell'originale e pertanto, può essere modificato senza modificare il nodo di partenza passato alla funzione. Se il nodo fornito, a sua volta, ha dei nodi figli, pure questi saranno duplicati, in questo modo è abbastanza semplice duplicare grandi parti di un documento XML. La funzione restituisce il nodo aggiunto. Se in seguito occorre modificare il nodo fratello che si è aggiunto, occorre utilizzare il nodo restituito.

Questa funzione è stata aggiunta per replicare il comportamento di domnode_append_child() che si ha fino alla versione 4.2 di PHP.

Vedere anche domnode_append_before().



add a note add a note User Contributed Notes
DomNode->append_sibling
s dot girard at pandora dot be
30-Apr-2004 11: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);
$page->set_attribute("pageimage","images/news.jpg");
   
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);
}
unlink("./data/news.xml");
$doc->dump_file("./data/news.xml");

DomNode->attributes> <DomNode->append_child
Last updated: Fri, 27 Jun 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites