downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DomDocument::dump_file> <DomDocument::doctype
[edit] Last updated: Fri, 25 May 2012

view this page in

DomDocument::document_element

(PHP 4 >= 4.1.0)

DomDocument::document_element Devuelve la raíz de nodo de elemento

Descripción

domelement DomDocument::document_element ( void )

Esta función devuelve el nodo de elemento raíz de un documento.

El ejemplo siguiente devuelve sólo el elemento con el nombre de CAPÍTULO y lo imprime. El otro nodo - el comentario - no se devuelve.

Ejemplo #1 Recuperar elemento raíz

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

if (!
$dom domxml_open_mem($xmlstr)) {
  echo 
"Error al analizar el documento\n";
  exit;
}

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

El resultado del ejemplo sería:

domelement Object
(
    [type] => 1
    [tagname] => capítulo
    [0] => 6
    [1] => 137960648
)



DomDocument::dump_file> <DomDocument::doctype
[edit] Last updated: Fri, 25 May 2012
 
add a note add a note User Contributed Notes DomDocument::document_element
jaworskidaniel no at spam gmail dot com 14-Jul-2008 05:19
in php5

            $root = $dom->documentElement;
            $tag = $root->tagName;
misterffoeg at hotmail dot com 11-Dec-2007 03: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 01-Apr-2007 05: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 02: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);

 
show source | credits | sitemap | contact | advertising | mirror sites