(PHP 5, PHP 7, PHP 8)
Represents an entire HTML or XML document; serves as the root of the document tree.
$namespace
, string $qualifiedName
, string $value
= ""): DOMElement|false$target
, string $data
= ""): DOMProcessingInstruction|false$exclusive
= false
,$withComments
= false
,$xpath
= null
,$nsPrefixes
= null
$uri
,$exclusive
= false
,$withComments
= false
,$xpath
= null
,$nsPrefixes
= null
Deprecated. Actual encoding of the document, is a readonly equivalent to encoding.
The number of child elements.
Deprecated. Configuration used when DOMDocument::normalizeDocument() is invoked.
The Document Type Declaration associated with this document.
The DOMElement object that is the first
document element. If not found, this evaluates to null
.
The location of the document or null
if undefined.
Encoding of the document, as specified by the XML declaration. This attribute is not present in the final DOM Level 3 specification, but is the only way of manipulating XML document encoding in this implementation.
First child element or null
.
Nicely formats output with indentation and extra space. This has no effect if the document was loaded with preserveWhitespace enabled.
The DOMImplementation object that handles this document.
Last child element or null
.
Do not remove redundant white space. Default to true
.
Setting this to false
has the same effect as passing LIBXML_NOBLANKS
as option
to DOMDocument::load() etc.
Proprietary. Enables recovery mode, i.e. trying to parse non-well formed documents. This attribute is not part of the DOM specification and is specific to libxml.
Set it to true
to load external entities from a doctype
declaration. This is useful for including character entities in
your XML document.
Deprecated. Whether or not the document is standalone, as specified by the XML declaration, corresponds to xmlStandalone.
Throws DOMException on errors. Default to true
.
Proprietary. Whether or not to substitute entities. This attribute is not part of the DOM specification and is specific to libxml.
Enabling entity substitution may facilitate XML External Entity (XXE) attacks.
Loads and validates against the DTD. Default to false
.
Deprecated. Version of XML, corresponds to xmlVersion.
An attribute specifying, as part of the XML declaration, the
encoding of this document. This is null
when unspecified or when it
is not known, such as when the Document was created in memory.
An attribute specifying, as part of the XML declaration, whether
this document is standalone. This is false
when unspecified.
An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0".
版本 | 说明 |
---|---|
8.0.0 | DOMDocument implements DOMParentNode now. |
8.0.0 | The unimplemented method DOMDocument::renameNode() has been removed. |
注意:
此 DOM 扩展采用 UTF-8 编码。在 ISO-8859-1 编码下,使用 utf8_encode() 和 utf8_decode() 来处理,其它编码下使用 iconv 函数处理。
注意:
When using json_encode() on a DOMDocument object the result will be that of encoding an empty object.