DomDocument->document_element

(no version information, 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
)


add a note add a note User Contributed Notes
Ian Cooper
16-Jul-2006 09:12
According to the manual, document_element is a function (in PHP4, at least).
MDummy
17-Mar-2006 11:55
document_element is not a funktion --> no clauses at the end!!

must be:
$root = $doc->document_element;