PHP : Function Reference : DOM XML Functions : DomNode->append_sibling
s dot girard
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");
|