# Document Object Model

# Introduction

The DOM extension allows operations on XML and HTML documents through the DOM API with PHP.

> Note:

> The DOM extension uses UTF-8 encoding. Use mb_convert_encoding(), UConverter::transcode(), or iconv() to handle other encodings.

- Installing/Configuring
  - Requirements
  - Installation
- Predefined Constants
- Examples
- DOMAttr — The DOMAttr class
  - DOMAttr::__construct — Creates a new DOMAttr object
  - DOMAttr::isId — Checks if attribute is a defined ID
- DOMCdataSection — The DOMCdataSection class
  - DOMCdataSection::__construct — Constructs a new DOMCdataSection object
- DOMCharacterData — The DOMCharacterData class
  - DOMCharacterData::after — Adds nodes after the character data
  - DOMCharacterData::appendData — Append the string to the end of the character data of the node
  - DOMCharacterData::before — Adds nodes before the character data
  - DOMCharacterData::deleteData — Remove a range of characters from the character data
  - DOMCharacterData::insertData — Insert a string at the specified UTF-8 codepoint offset
  - DOMCharacterData::remove — Removes the character data node
  - DOMCharacterData::replaceData — Replace a substring within the character data
  - DOMCharacterData::replaceWith — Replaces the character data with new nodes
  - DOMCharacterData::substringData — Extracts a range of data from the character data
- DOMChildNode — The DOMChildNode interface
  - DOMChildNode::after — Adds nodes after the node
  - DOMChildNode::before — Adds nodes before the node
  - DOMChildNode::remove — Removes the node
  - DOMChildNode::replaceWith — Replaces the node with new nodes
- DOMComment — The DOMComment class
  - DOMComment::__construct — Creates a new DOMComment object
- DOMDocument — The DOMDocument class
  - DOMDocument::adoptNode — Transfer a node from another document
  - DOMDocument::append — Appends nodes after the last child node
  - 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::prepend — Prepends nodes before the first child node
  - 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::replaceChildren — Replace children in 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. Only XML Schema 1.0 is supported.
  - 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
- DOMDocumentFragment — The DOMDocumentFragment class
  - DOMDocumentFragment::append — Appends nodes after the last child node
  - DOMDocumentFragment::appendXML — Append raw XML data
  - DOMDocumentFragment::__construct — Constructs a DOMDocumentFragment object
  - DOMDocumentFragment::prepend — Prepends nodes before the first child node
  - DOMDocumentFragment::replaceChildren — Replace children in fragment
- DOMDocumentType — The DOMDocumentType class
- DOMElement — The DOMElement class
  - DOMElement::after — Adds nodes after the element
  - DOMElement::append — Appends nodes after the last child node
  - DOMElement::before — Adds nodes before the element
  - DOMElement::__construct — Creates a new DOMElement object
  - DOMElement::getAttribute — Returns value of attribute
  - DOMElement::getAttributeNames — Get attribute names
  - DOMElement::getAttributeNode — Returns attribute node
  - DOMElement::getAttributeNodeNS — Returns attribute node
  - DOMElement::getAttributeNS — Returns value of attribute
  - DOMElement::getElementsByTagName — Gets elements by tagname
  - DOMElement::getElementsByTagNameNS — Get elements by namespaceURI and localName
  - DOMElement::hasAttribute — Checks to see if attribute exists
  - DOMElement::hasAttributeNS — Checks to see if attribute exists
  - DOMElement::insertAdjacentElement — Insert adjacent element
  - DOMElement::insertAdjacentText — Insert adjacent text
  - DOMElement::prepend — Prepends nodes before the first child node
  - DOMElement::remove — Removes the element
  - DOMElement::removeAttribute — Removes attribute
  - DOMElement::removeAttributeNode — Removes attribute
  - DOMElement::removeAttributeNS — Removes attribute
  - DOMElement::replaceChildren — Replace children in element
  - DOMElement::replaceWith — Replaces the element with new nodes
  - DOMElement::setAttribute — Adds new or modifies existing attribute
  - DOMElement::setAttributeNode — Adds new attribute node to element
  - DOMElement::setAttributeNodeNS — Adds new attribute node to element
  - DOMElement::setAttributeNS — Adds new attribute
  - DOMElement::setIdAttribute — Declares the attribute specified by name to be of type ID
  - DOMElement::setIdAttributeNode — Declares the attribute specified by node to be of type ID
  - DOMElement::setIdAttributeNS — Declares the attribute specified by local name and namespace URI to be of type ID
  - DOMElement::toggleAttribute — Toggle attribute
- DOMEntity — The DOMEntity class
- DOMEntityReference — The DOMEntityReference class
  - DOMEntityReference::__construct — Creates a new DOMEntityReference object
- DOMException — The DOMException / Dom\Exception class
- DOMImplementation — The DOMImplementation class
  - DOMImplementation::__construct — Creates a new DOMImplementation object
  - DOMImplementation::createDocument — Creates a DOMDocument object of the specified type with its document element
  - DOMImplementation::createDocumentType — Creates an empty DOMDocumentType object
  - DOMImplementation::hasFeature — Test if the DOM implementation implements a specific feature
- DOMNamedNodeMap — The DOMNamedNodeMap class
  - DOMNamedNodeMap::count — Get number of nodes in the map
  - DOMNamedNodeMap::getIterator — Retrieve an external iterator
  - DOMNamedNodeMap::getNamedItem — Retrieves a node specified by name
  - DOMNamedNodeMap::getNamedItemNS — Retrieves a node specified by local name and namespace URI
  - DOMNamedNodeMap::item — Retrieves a node specified by index
- DOMNameSpaceNode — The DOMNameSpaceNode class
  - DOMNameSpaceNode::__sleep — Forbids serialization unless serialization methods are implemented in a subclass
  - DOMNameSpaceNode::__wakeup — Forbids unserialization unless unserialization methods are implemented in a subclass
- DOMNode — The DOMNode class
  - DOMNode::appendChild — Adds new child at the end of the children
  - DOMNode::C14N — Canonicalize nodes to a string
  - DOMNode::C14NFile — Canonicalize nodes to a file
  - DOMNode::cloneNode — Clones a node
  - DOMNode::compareDocumentPosition — Compares the position of two nodes
  - DOMNode::contains — Checks if node contains other node
  - DOMNode::getLineNo — Get line number for a node
  - DOMNode::getNodePath — Get an XPath for a node
  - DOMNode::getRootNode — Get root node
  - DOMNode::hasAttributes — Checks if node has attributes
  - DOMNode::hasChildNodes — Checks if node has children
  - DOMNode::insertBefore — Adds a new child before a reference node
  - DOMNode::isDefaultNamespace — Checks if the specified namespaceURI is the default namespace or not
  - DOMNode::isEqualNode — Checks that both nodes are equal
  - DOMNode::isSameNode — Indicates if two nodes are the same node
  - DOMNode::isSupported — Checks if feature is supported for specified version
  - DOMNode::lookupNamespaceURI — Gets the namespace URI of the node based on the prefix
  - DOMNode::lookupPrefix — Gets the namespace prefix of the node based on the namespace URI
  - DOMNode::normalize — Normalizes the node
  - DOMNode::removeChild — Removes child from list of children
  - DOMNode::replaceChild — Replaces a child
  - DOMNode::__sleep — Forbids serialization unless serialization methods are implemented in a subclass
  - DOMNode::__wakeup — Forbids unserialization unless unserialization methods are implemented in a subclass
- DOMNodeList — The DOMNodeList class
  - DOMNodeList::count — Get number of nodes in the list
  - DOMNodeList::getIterator — Retrieve an external iterator
  - DOMNodeList::item — Retrieves a node specified by index
- DOMNotation — The DOMNotation class
- DOMParentNode — The DOMParentNode interface
  - DOMParentNode::append — Appends nodes after the last child node
  - DOMParentNode::prepend — Prepends nodes before the first child node
  - DOMParentNode::replaceChildren — Replace children in node
- DOMProcessingInstruction — The DOMProcessingInstruction class
  - DOMProcessingInstruction::__construct — Creates a new DOMProcessingInstruction object
- DOMText — The DOMText class
  - DOMText::__construct — Creates a new DOMText object
  - DOMText::isElementContentWhitespace — Returns whether this text node contains whitespace in element content
  - DOMText::isWhitespaceInElementContent — Indicates whether this text node contains whitespace
  - DOMText::splitText — Breaks this node into two nodes at the specified offset
- DOMXPath — The DOMXPath class
  - DOMXPath::__construct — Creates a new DOMXPath object
  - DOMXPath::evaluate — Evaluates the given XPath expression and returns a typed result if possible
  - DOMXPath::query — Evaluates the given XPath expression
  - DOMXPath::quote — Quotes a string for use in an XPath expression
  - DOMXPath::registerNamespace — Registers the namespace with the DOMXPath object
  - DOMXPath::registerPhpFunctionNS — Register a PHP functions as namespaced XPath function
  - DOMXPath::registerPhpFunctions — Register PHP functions as XPath functions
- Dom\AdjacentPosition — The Dom\AdjacentPosition Enum
- Dom\Attr — The Dom\Attr class
  - Dom\Attr::isId — Checks if attribute is a defined ID
  - Dom\Attr::rename — Changes the qualified name or namespace of an attribute
- Dom\CDATASection — The Dom\CDATASection class
- Dom\CharacterData — The Dom\CharacterData class
  - Dom\CharacterData::after — Adds nodes after the character data
  - Dom\CharacterData::appendData — Append the string to the end of the character data of the node
  - Dom\CharacterData::before — Adds nodes before the character data
  - Dom\CharacterData::deleteData — Remove a range of characters from the character data
  - Dom\CharacterData::insertData — Insert a string at the specified UTF-8 codepoint offset
  - Dom\CharacterData::remove — Removes the character data node
  - Dom\CharacterData::replaceData — Replace a substring within the character data
  - Dom\CharacterData::replaceWith — Replaces the character data with new nodes
  - Dom\CharacterData::substringData — Extracts a range of data from the character data
- Dom\ChildNode — The Dom\ChildNode interface
  - Dom\ChildNode::after — Adds nodes after the node
  - Dom\ChildNode::before — Adds nodes before the node
  - Dom\ChildNode::remove — Removes the node
  - Dom\ChildNode::replaceWith — Replaces the node with new nodes
- Dom\Comment — The Dom\Comment class
- Dom\Document — The Dom\Document class
- Dom\DocumentFragment — The Dom\DocumentFragment class
- Dom\DocumentType — The Dom\DocumentType class
- Dom\DtdNamedNodeMap — The Dom\DtdNamedNodeMap class
- Dom\Element — The Dom\Element class
- Dom\Entity — The Dom\Entity class
- Dom\EntityReference — The Dom\EntityReference class
- Dom\HTMLCollection — The Dom\HTMLCollection class
- Dom\HTMLDocument — The Dom\HTMLDocument class
  - Dom\HTMLDocument::createEmpty — Creates an empty HTML document
  - Dom\HTMLDocument::createFromFile — Parses an HTML document from a file
  - Dom\HTMLDocument::createFromString — Parses an HTML document from a string
  - Dom\HTMLDocument::saveHtml — Serializes the document as an HTML string
  - Dom\HTMLDocument::saveHtmlFile — Serializes the document as an HTML file
  - Dom\HTMLDocument::saveXml — Serializes the document as an XML string
  - Dom\HTMLDocument::saveXmlFile — Serializes the document as an XML file
- Dom\HTMLElement — The Dom\HTMLElement class
- Dom\Implementation — The Dom\Implementation class
- Dom\NamedNodeMap — The Dom\NamedNodeMap class
- Dom\NamespaceInfo — The Dom\NamespaceInfo class
- Dom\Node — The Dom\Node class
- Dom\NodeList — The Dom\NodeList class
- Dom\Notation — The Dom\Notation class
- Dom\ParentNode — The Dom\ParentNode interface
  - Dom\ParentNode::append — Appends nodes after the last child node
  - Dom\ParentNode::prepend — Prepends nodes before the first child node
  - Dom\ParentNode::querySelector — Returns the first element that matches the CSS selectors
  - Dom\ParentNode::querySelectorAll — Returns a collection of elements that match the CSS selectors
  - Dom\ParentNode::replaceChildren — Replace children in node
- Dom\ProcessingInstruction — The Dom\ProcessingInstruction class
- Dom\Text — The Dom\Text class
  - Dom\Text::splitText — Breaks this node into two nodes at the specified offset
- Dom\TokenList — The Dom\TokenList class
  - Dom\TokenList::add — Adds the given tokens to the list
  - Dom\TokenList::contains — Returns whether the list contains a given token
  - Dom\TokenList::count — Returns the number of tokens in the list
  - Dom\TokenList::getIterator — Returns an iterator over the token list
  - Dom\TokenList::item — Returns a token from the list
  - Dom\TokenList::remove — Removes the given tokens from the list
  - Dom\TokenList::replace — Replaces a token in the list with another one
  - Dom\TokenList::supports — Returns whether the given token is supported
  - Dom\TokenList::toggle — Toggles the presence of a token in the list
- Dom\XMLDocument — The Dom\XMLDocument class
- Dom\XPath — The Dom\XPath class
- DOM Functions
  - dom_import_simplexml — Gets a DOMAttr or DOMElement object from a SimpleXMLElement object
  - Dom\import_simplexml — Gets a Dom\Attr or Dom\Element object from a SimpleXMLElement object

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open