The DOMDocument class
(PHP 5, PHP 7)
Introduction
Represents an entire HTML or XML document; serves as the root of the document tree.
Class synopsis
$namespaceURI
, string $qualifiedName
[, string $value
] ) : DOMElement$exclusive
[, bool $with_comments
[, array $xpath
[, array $ns_prefixes
]]]] ) : string$uri
[, bool $exclusive
= FALSE
[, bool $with_comments
= FALSE
[, array $xpath
[, array $ns_prefixes
]]]] ) : intProperties
- actualEncoding
-
Deprecated. Actual encoding of the document, is a readonly equivalent to encoding.
- config
-
Deprecated. Configuration used when DOMDocument::normalizeDocument() is invoked.
- doctype
-
The Document Type Declaration associated with this document.
- documentElement
-
This is a convenience attribute that allows direct access to the child node that is the document element of the document.
- documentURI
-
The location of the document or
NULL
if undefined. - encoding
-
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.
- formatOutput
-
Nicely formats output with indentation and extra space.
- implementation
-
The DOMImplementation object that handles this document.
- preserveWhiteSpace
-
Do not remove redundant white space. Default to
TRUE
. - recover
-
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.
- resolveExternals
-
Set it to
TRUE
to load external entities from a doctype declaration. This is useful for including character entities in your XML document. - standalone
-
Deprecated. Whether or not the document is standalone, as specified by the XML declaration, corresponds to xmlStandalone.
- strictErrorChecking
-
Throws DOMException on errors. Default to
TRUE
. - substituteEntities
-
Proprietary. Whether or not to substitute entities. This attribute is not part of the DOM specification and is specific to libxml.
- validateOnParse
-
Loads and validates against the DTD. Default to
FALSE
. - version
-
Deprecated. Version of XML, corresponds to xmlVersion.
- xmlEncoding
-
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. - xmlStandalone
-
An attribute specifying, as part of the XML declaration, whether this document is standalone. This is
FALSE
when unspecified. - xmlVersion
-
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".
Notes
Note:
The DOM extension uses UTF-8 encoding. Use utf8_encode() and utf8_decode() to work with texts in ISO-8859-1 encoding or Iconv for other encodings.
Table of Contents
- DOMDocument::__construct — Creates a new DOMDocument object
- DOMDocument::createAttribute — Create new attribute
- DOMDocument::createAttributeNS — Create new attribute node with an associated namespace
- DOMDocument::createCDATASection — Create new cdata node
- DOMDocument::createComment — Create new comment node
- DOMDocument::createDocumentFragment — Create new document fragment
- DOMDocument::createElement — Create new element node
- DOMDocument::createElementNS — Create new element node with an associated namespace
- DOMDocument::createEntityReference — Create new entity reference node
- DOMDocument::createProcessingInstruction — Creates new PI node
- DOMDocument::createTextNode — Create new text node
- DOMDocument::getElementById — Searches for an element with a certain id
- DOMDocument::getElementsByTagName — Searches for all elements with given local tag name
- DOMDocument::getElementsByTagNameNS — Searches for all elements with given tag name in specified namespace
- DOMDocument::importNode — Import node into current document
- DOMDocument::load — Load XML from a file
- DOMDocument::loadHTML — Load HTML from a string
- DOMDocument::loadHTMLFile — Load HTML from a file
- DOMDocument::loadXML — Load XML from a string
- DOMDocument::normalizeDocument — Normalizes the document
- DOMDocument::registerNodeClass — Register extended class used to create base node type
- DOMDocument::relaxNGValidate — Performs relaxNG validation on the document
- DOMDocument::relaxNGValidateSource — Performs relaxNG validation on the document
- DOMDocument::save — Dumps the internal XML tree back into a file
- DOMDocument::saveHTML — Dumps the internal document into a string using HTML formatting
- DOMDocument::saveHTMLFile — Dumps the internal document into a file using HTML formatting
- DOMDocument::saveXML — Dumps the internal XML tree back into a string
- DOMDocument::schemaValidate — Validates a document based on a schema
- DOMDocument::schemaValidateSource — Validates a document based on a schema
- DOMDocument::validate — Validates the document based on its DTD
- DOMDocument::xinclude — Substitutes XIncludes in a DOMDocument Object
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.domdocument.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.