PHP Manual

The DOMDocument class

(PHP 5, PHP 7)


Represents an entire HTML or XML document; serves as the root of the document tree.

Class synopsis

DOMDocument extends DOMNode {
/* Properties */
readonly public string $actualEncoding ;
readonly public DOMConfiguration $config ;
readonly public DOMDocumentType $doctype ;
readonly public DOMElement $documentElement ;
public string $documentURI ;
public string $encoding ;
public bool $formatOutput ;
public bool $preserveWhiteSpace = true ;
public bool $recover ;
public bool $resolveExternals ;
public bool $standalone ;
public bool $strictErrorChecking = true ;
public bool $substituteEntities ;
public bool $validateOnParse = false ;
public string $version ;
readonly public string $xmlEncoding ;
public bool $xmlStandalone ;
public string $xmlVersion ;
/* Methods */
public __construct ([ string $version [, string $encoding ]] )
public DOMAttr createAttribute ( string $name )
public DOMAttr createAttributeNS ( string $namespaceURI , string $qualifiedName )
public DOMCDATASection createCDATASection ( string $data )
public DOMComment createComment ( string $data )
public DOMDocumentFragment createDocumentFragment ( void )
public DOMElement createElement ( string $name [, string $value ] )
public DOMElement createElementNS ( string $namespaceURI , string $qualifiedName [, string $value ] )
public DOMEntityReference createEntityReference ( string $name )
public DOMProcessingInstruction createProcessingInstruction ( string $target [, string $data ] )
public DOMText createTextNode ( string $content )
public DOMElement getElementById ( string $elementId )
public DOMNodeList getElementsByTagName ( string $name )
public DOMNodeList getElementsByTagNameNS ( string $namespaceURI , string $localName )
public DOMNode importNode ( DOMNode $importedNode [, bool $deep ] )
public mixed load ( string $filename [, int $options = 0 ] )
public bool loadHTML ( string $source [, int $options = 0 ] )
public bool loadHTMLFile ( string $filename [, int $options = 0 ] )
public mixed loadXML ( string $source [, int $options = 0 ] )
public void normalizeDocument ( void )
public bool registerNodeClass ( string $baseclass , string $extendedclass )
public bool relaxNGValidate ( string $filename )
public bool relaxNGValidateSource ( string $source )
public int save ( string $filename [, int $options ] )
public string saveHTML ([ DOMNode $node = NULL ] )
public int saveHTMLFile ( string $filename )
public string saveXML ([ DOMNode $node [, int $options ]] )
public bool schemaValidate ( string $filename [, int $flags ] )
public bool schemaValidateSource ( string $source [, int $flags ] )
public bool validate ( void )
public int xinclude ([ int $options ] )
/* Inherited methods */
public DOMNode DOMNode::appendChild ( DOMNode $newnode )
public string DOMNode::C14N ([ bool $exclusive [, bool $with_comments [, array $xpath [, array $ns_prefixes ]]]] )
public int DOMNode::C14NFile ( string $uri [, bool $exclusive [, bool $with_comments [, array $xpath [, array $ns_prefixes ]]]] )
public DOMNode DOMNode::cloneNode ([ bool $deep ] )
public int DOMNode::getLineNo ( void )
public string DOMNode::getNodePath ( void )
public bool DOMNode::hasAttributes ( void )
public bool DOMNode::hasChildNodes ( void )
public DOMNode DOMNode::insertBefore ( DOMNode $newnode [, DOMNode $refnode ] )
public bool DOMNode::isDefaultNamespace ( string $namespaceURI )
public bool DOMNode::isSameNode ( DOMNode $node )
public bool DOMNode::isSupported ( string $feature , string $version )
public string DOMNode::lookupNamespaceURI ( string $prefix )
public string DOMNode::lookupPrefix ( string $namespaceURI )
public void DOMNode::normalize ( void )
public DOMNode DOMNode::removeChild ( DOMNode $oldnode )
public DOMNode DOMNode::replaceChild ( DOMNode $newnode , DOMNode $oldnode )



Deprecated. Actual encoding of the document, is a readonly equivalent to encoding.


Deprecated. Configuration used when DOMDocument::normalizeDocument() is invoked.


The Document Type Declaration associated with this document.


This is a convenience attribute that allows direct access to the child node that is the document element of the document.


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.


Nicely formats output with indentation and extra space.


The DOMImplementation object that handles this document.


Do not remove redundant white space. Default to TRUE.


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.


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".



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

PHP Manual