|
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()
cannot be applied to it. Therefore, if you want to read
an XML file and write a modified version, use DomDocument_create_element(), DomDocument_create_text_node(), set_attribute(), etc. and finally
the DomDocument_dump_mem()
function.
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 extension is only available if PHP was
configured with
--with-dom[=DIR]. Add
--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.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libxml2.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM32)
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
DomNode_append_sibling().
表格 1. Deprecated functions and their
replacements
以下的常數由此延伸定義, 只在這個延伸被編譯成PHP或實行時期被動態載入時有效。
表格 2. XML constants
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 compatibilty to
older versions of the extension, and should not be used
when creating new scripts.
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 — including their method — in the following
tables. Classes with an equivalent in the DOM standard
are named DOMxxx.
表格 3. List of classes
表格 4. DomDocument class (DomDocument :
DomNode)
表格 5. DomElement class (DomElement :
DomNode)
表格 6. DomNode class
表格 7. DomAttribute class (DomAttribute :
DomNode)
表格 8. DomProcessingInstruction class
(DomProcessingInstruction : DomNode)
表格 10. XPathContext class
表格 11. DomDocumentType class (DomDocumentType :
DomNode)
The classes DomDtd is derived from DomNode.
DomComment is derived from DomCData.
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().