(PHP 4 >= 4.0.0)

domxml_root --  Returns root element node


object domxml_root (object doc)


This function is EXPERIMENTAL. That means, that the behaviour of this function, this function name, in concreto ANYTHING documented here can change in a future release of PHP WITHOUT NOTICE. Be warned, and use this function at your own risk.

domxml_root() takes one argument, an object of class "Dom document", and returns the root element node. There are actually other possible nodes like comments which are currently disregarded.

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

Example 1. Retrieving root element

$xmlstr = "<?xml version='1.0' standalone='yes'?>
<!DOCTYPE chapter SYSTEM '/share/sgml/Norman_Walsh/db3xml10/db3xml10.dtd'
[ <!ENTITY sp \"spanish\">
<!-- lsfj  -->
<chapter language='en'><title language='en'>Title</title>
 <para language='ge'>
  <!-- comment -->
  <informaltable language='&sp;'>
   <tgroup cols='3'>

if(!$dom = xmldoc($xmlstr)) {
  echo "Error while parsing the document\n";

$root = $dom->root();
/* or $root = domxml_root($dom); */