The DOMDocument class
Represents an entire HTML or XML document; serves as the root of the document tree.
Intro
Represents an entire HTML or XML document; serves as the root of the document tree.
Class synopsis
Properties
actualEncodingDeprecated as of PHP 8.4.0. Actual encoding of the document, is a readonly equivalent to
encoding.childElementCountThe number of child elements.
configDeprecated as of PHP 8.4.0. Configuration used when
DOMDocument::normalizeDocument()is invoked.doctypeThe Document Type Declaration associated with this document.
documentElementThe
DOMElementobject that is the first document element. If not found, this evaluates to null.documentURIThe location of the document or null if undefined.
encodingEncoding 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.
firstElementChildFirst child element or null.
formatOutputNicely formats output with indentation and extra space. This has no effect if the document was loaded with
preserveWhitespaceenabled.implementationThe
DOMImplementationobject that handles this document.lastElementChildLast child element or null.
preserveWhiteSpaceDo not remove redundant white space. Default to true. Setting this to false has the same effect as passing
LIBXML_NOBLANKSasoptiontoDOMDocument::loadetc.recoverProprietary. 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.
resolveExternalsSet it to true to load external entities from a doctype declaration. This is useful for including character entities in your XML document.
standaloneDeprecated. Whether or not the document is standalone, as specified by the XML declaration, corresponds to
xmlStandalone.strictErrorCheckingThrows
DOMExceptionon errors. Default to true.substituteEntitiesProprietary. Whether or not to substitute entities. This attribute is not part of the DOM specification and is specific to libxml. Default to false.
CautionEnabling entity substitution may facilitate XML External Entity (XXE) attacks.
validateOnParseLoads and validates against the DTD. Default to false.
CautionEnabling validating the DTD may facilitate XML External Entity (XXE) attacks.
versionDeprecated. Version of XML, corresponds to
xmlVersion.xmlEncodingAn 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.
xmlStandaloneAn attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified. A standalone document is one where there are no external markup declarations. An example of such a markup declaration is when the DTD declares an attribute with a default value.
xmlVersionAn 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".
Changelog
| Version | Description |
|---|---|
| 8.4.0 | actualEncoding and config are formally deprecated now. |
| 8.0.0 | DOMDocument implements DOMParentNode now. |
| 8.0.0 | The unimplemented method DOMDocument::renameNode has been removed. |
Notes Utf8 Json
See Also
- W3C specification for Document
Domdocument