DomDocument->document_element

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

DomDocument->document_element — Returns root element node

Описание

domelement DomDocument->document_element ( void )

This function returns the root element node of a document.

The following example returns just the element with name CHAPTER and prints it. The other node -- the comment -- is not returned.

Пример #1 Retrieving root element

<?php
include("example.inc");

if (!
$dom domxml_open_mem($xmlstr)) {
  echo 
"Error while parsing the document\n";
  exit;
}

$root $dom->document_element();
print_r($root);
?>

Результат выполнения данного примера:

domelement Object
(
    [type] => 1
    [tagname] => chapter
    [0] => 6
    [1] => 137960648
)

[an error occurred while processing the directive]

Коментарии

as of PHP 5 (tested with 5.1.4), remember to use documentElement instead. As in:
$dom = new DomDocument ();
$dom -> load ('file.xml');
$newEl = $dom -> createElement ('newEl');
$dom -> documentElement -> appendChild ($newEl);
2006-12-30 04:29:28
http://php5.kiev.ua/manual/ru/function.domdocument-document-element.html
The last note is incorrect. The class he is referring to is DOMDocument, not DomDocument. This page is for the PHP 4 extension. Doing "new DomDocument" would be a fatal error in PHP 5 unless you hacked the old extension into it which would be a very useless move.
2007-12-11 05:03:35
http://php5.kiev.ua/manual/ru/function.domdocument-document-element.html
in php5

            $root = $dom->documentElement;
            $tag = $root->tagName;
2008-07-14 08:19:37
http://php5.kiev.ua/manual/ru/function.domdocument-document-element.html

    Поддержать сайт на родительском проекте КГБ