DOM XML (PHP 4) 函数
在线手册:中文 英文
PHP手册

DomDocument::add_root

(PHP 4 >= 4.1.0)

DomDocument::add_root Adds a root node [deprecated]

说明

domelement DomDocument::add_root ( string $name )

Adds a root element node to a dom document and returns the new node. The element name is given in the passed parameter.

Example #1 Creating a simple HTML document header

<?php
$doc 
domxml_new_doc("1.0");
$root $doc->add_root("html");
$head $root->new_child("head""");
$head->new_child("title""Hier der Titel");
echo 
htmlentities($doc->dump_mem());
?>


DOM XML (PHP 4) 函数
在线手册:中文 英文
PHP手册
PHP手册 - N: Adds a root node [deprecated]

用户评论:

Jorrit Kronjee (05-Nov-2003 03:16)

For those not closely reading the documentation (like me), this is an example of adding a root without add_root.

$new_dom = domxml_new_doc("1.0");
$new_element = $newdom->create_element("root_el");
$new_node = $newdom->append_child($new_element);