This extension is
EXPERIMENTAL. The behaviour of this extension --
including the names of its functions and anything else documented
about this extension -- may change without notice in a future release of PHP.
Use this extension at your own risk.
The DOM XML extension has been overhauled in PHP 4.3.0 to better comply with
the DOM standard. The extension still contains
many old functions, but they should no longer be used. In particular, functions
that are not object-oriented should be avoided.
The extension allows you to operate on an XML document with the DOM API.
It also provides a function domxml_xmltree() to turn the
complete XML document into a tree of PHP objects. Currently, this
tree should be considered read-only - you can modify it, but this
would not make any sense since DomDocument_dump_mem()
applied to it. Therefore, if you want to read an XML file and write
a modified version, use DomDocument_create_element(),
set_attribute(), etc. and finally the
This extension has been removed as of PHP 5 and moved to the
If you need DOM XML support with PHP 5 you can use the
This extension makes use of the
GNOME XML library. Download
and install this library. You will need at least libxml-2.4.14.
To use DOM XSLT features you can use the
libxslt library and EXSLT
enhancements from http://www.exslt.org/.
Download and install these libraries if you plan to use (enhanced) XSLT
features. You will need at least libxslt-1.0.18.
This PECL extension
is not bundled with PHP.
Additional information such as new releases,
downloads, source files, maintainer information, and a CHANGELOG, can be
In PHP 4 this PECL extensions
source can be found in the ext/ directory within the
PHP source or at the PECL link above.
This extension is only available if PHP was configured with
--with-dom-xslt[=DIR] to include DOM
XSLT support. DIR is the libxslt install directory. Add
--with-dom-exslt[=DIR] to include DOM
EXSLT support, where DIR is the libexslt install directory.
Windows users will enable php_domxml.dll inside
of php.ini in order to use these functions.
In PHP 4 this DLL resides in
the extensions/ directory within the PHP Windows
You may download this PECL
extensions DLL from the
PHP Downloads page or at
Also, there is one additional DLL that must be made available to your
system's PATH in order for this extension to work. In PHP 4 this is
in the dlls/ directory. It's name:
For PHP <= 4.2.0, it's libxml2.dll.
For PHP >= 4.3.0, it's iconv.dll.
And as of PHP 5.0.0, iconv is compiled into your Windows PHP binaries by
default so no extra DLL is needed.
There are quite a few functions that do not fit into the DOM standard and
should no longer be used. These functions are listed in the following table.
The function DomNode_append_child() has changed its
behaviour. It now adds a child and not a sibling. If this
breaks your application, use the non-DOM function
Table 1. Deprecated functions and their replacements
The constants below are defined by this extension, and
will only be available when the extension has either
been compiled into PHP or dynamically loaded at runtime.
The API of the module follows the DOM Level 2 standard as closely
as possible. Consequently, the API is fully object-oriented.
It is a good idea to have the DOM standard available when
using this module.
Though the API is object-oriented, there are many functions which can
be called in a non-object-oriented way by passing the object to operate
on as the first argument. These functions are mainly to retain compatibility
to older versions of the extension, and should not be used when creating new
This API differs from the official DOM API in two ways. First, all
class attributes are implemented as functions with the same name.
Secondly, the function names follow the PHP naming convention. This means
that a DOM function lastChild() will be written as last_child().
This module defines a number of classes, which are listed -
method - in the following tables. Classes with an equivalent in the
DOM standard are named DOMxxx.
Table 3. List of classes
|Class name||Parent classes|
|DomComment||DomCData : DomNode|
|DomText||DomCData : DomNode|
|Parser||Currently still called DomParser|
Table 4. DomDocument class (DomDocument : DomNode)
Table 5. DomElement class (DomElement : DomNode)
Table 7. DomAttribute class (DomAttribute : DomNode)
Table 8. DomProcessingInstruction class (DomProcessingInstruction : DomNode)
Table 9. Parser class
|Method name||Function name||Remark|
Table 10. XPathContext class
|Method name||Function name||Remark|
Table 11. DomDocumentType class (DomDocumentType : DomNode)
The classes DomDtd is derived from DomNode. DomComment is derived from
Many examples in this reference require an XML string. Instead of
repeating this string in every example, it will be put into a file
which will be included by each example. This include file is shown in the
following example section. Alternatively, you could create an XML document and
read it with DomDocument_open_file().
Example 1. Include file example.inc with XML string
$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>
<!-- comment -->
<informaltable ID='findme' language='&sp;'>