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::append_sibling
(PHP 4 >= 4.2.0)
DomNode::append_sibling — Agrega un nuevo hermano a un nodo
Descripción
Esta función agrega un hermano a un nodo existente. El hijo puede ser creado con domdocument_create_element(), domdocument_create_text() etc. o simplemente utilizando cualquier otro nodo.
Antes que un nuevo hermano sea agregado es primero duplicado. Por lo que el nuevo hijo es una copia completamente nueva que puede ser modificada sin cambiar el nodo que fue pasado a la función. Si el nodo pasado tiene hijos, ellos serán duplicados también, lo que hace simple duplicar grandes partes de un documento XML. El valor de retorno es el hermano agregado. Si planea realizar nuevas modificaciones al nodo agregado debe usar el nodo retornado.
Esta función ha sido agregada para proveer el comportamiento de domnode_append_child() hasta PHP 4.2.
Véase también domnode_append_before().
