in php5
$root = $dom->documentElement;
$tag = $root->tagName;
DomDocument->document_element
(No version information available, might be only in CVS)
DomDocument->document_element — Restituisce il nodo radice
Descrizione
Questa funzione restituisce il nodo radice di un documento.
Nell'esempio seguente la funzione restituisce l'elemento con nome CHAPTER. L'altro nodo -- the comment -- non viene restituito.
Example #1 Recupero dell'elemento radice
<?php
include("example.inc");
if (!$dom = domxml_open_mem($xmlstr)) {
echo "Errore nel parsing del documento\n";
exit;
}
$root = $dom->document_element();
print_r($root);
?>
Il precedente esempio visualizzerĂ :
domelement Object ( [type] => 1 [tagname] => chapter [0] => 6 [1] => 137960648 )
DomDocument->document_element
jaworskidaniel no at spam gmail dot com
14-Jul-2008 02:19
14-Jul-2008 02:19
misterffoeg at hotmail dot com
11-Dec-2007 12:03
11-Dec-2007 12:03
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.
rianfowler no at spam gmail dot com
02-Apr-2007 02:51
02-Apr-2007 02:51
The domelement returned by this will function as a domnode object for things like ->append_child.
$nodeChild = myxmldoc->create_element('child');
$nodeRoot = $this->myxmldoc->document_element();
$nodeRoot->append_child($nodeChild);
filipp at mac dot com
30-Dec-2006 11:29
30-Dec-2006 11:29
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);
