Parsoid
A bidirectional parser between wikitext and HTML5
Parsoid\Utils\DOMCompat Class Reference

Helper class that provides missing DOM level 3 methods for the PHP DOM classes. More...

Static Public Member Functions

static getTitle (DOMDocument $document)
 Get document title. More...
 
static setTitle (DOMDocument $document, string $title)
 Set document title. More...
 
static getElementById (DOMNode $node, string $id)
 Return the descendant with the specified ID. More...
 
static setIdAttribute (DOMElement $element, string $id)
 Workaround bug in PHP's Document::getElementById() which doesn't actually index the 'id' attribute unless you use the non-standard DOMElement::setIdAttribute method after the attribute is set; see https://www.php.net/manual/en/domdocument.getelementbyid.php for more details. More...
 
static attributes (DOMElement $element)
 Workaround bug in PHP's DOMElement::$attributes that fails to enumerate attributes named xmlns. More...
 
static hasAttributes (DOMElement $element)
 Workaround bug in PHP's DOMElement::hasAttributes() that fails to enumerate attributes named xmlns. More...
 
static getElementsByTagName (DOMNode $node, string $tagName)
 Return all descendants with the specified tag name. More...
 
static getLastElementChild (DOMNode $node)
 Return the last child of the node that is an Element, or null otherwise. More...
 
static querySelector (DOMNode $node, string $selector)
 
static querySelectorAll (DOMNode $node, string $selector)
 
static getPreviousElementSibling (DOMNode $node)
 Return the last preceding sibling of the node that is an element, or null otherwise. More...
 
static getNextElementSibling (DOMNode $node)
 Return the first following sibling of the node that is an element, or null otherwise. More...
 
static remove (DOMNode $node)
 Removes the node from the document. More...
 
static getInnerHTML (DOMElement $element)
 Get innerHTML. More...
 
static setInnerHTML (DOMElement $element, string $html)
 Set innerHTML. More...
 
static getOuterHTML (DOMElement $element)
 Get outerHTML. More...
 
static getClassList (DOMElement $node)
 Return the class list of this element. More...
 
static normalize (DOMElement $elt)
 

Detailed Description

Helper class that provides missing DOM level 3 methods for the PHP DOM classes.

For a DOM method $node->foo( $bar) the equivalent helper is DOMCompat::foo( $node, $bar ). For a DOM property $node->foo there is a DOMCompat::getFoo( $node ) and DOMCompat::setFoo( $node, $value ). Only implements the methods that are actually used by Parsoid.

Member Function Documentation

◆ attributes()

static Parsoid\Utils\DOMCompat::attributes ( DOMElement  $element)
static

Workaround bug in PHP's DOMElement::$attributes that fails to enumerate attributes named xmlns.

Parameters
DOMElement$element
Returns
DOMAttr[]
See also
https://phabricator.wikimedia.org/T235295

◆ getClassList()

static Parsoid\Utils\DOMCompat::getClassList ( DOMElement  $node)
static

Return the class list of this element.

Parameters
DOMElement$node
Returns
TokenList
See also
https://dom.spec.whatwg.org/#dom-element-classlist

◆ getElementById()

static Parsoid\Utils\DOMCompat::getElementById ( DOMNode  $node,
string  $id 
)
static

Return the descendant with the specified ID.

Workaround for https://bugs.php.net/bug.php?id=77686 and other issues related to inconsistent indexing behavior.

Parameters
DOMDocument | DOMDocumentFragment$node
string$id
Returns
DOMElement|null
See also
https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid

◆ getElementsByTagName()

static Parsoid\Utils\DOMCompat::getElementsByTagName ( DOMNode  $node,
string  $tagName 
)
static

Return all descendants with the specified tag name.

Workaround for PHP's getElementsByTagName being inexplicably slow in some situations and the lack of DOMElement::getElementsByTagName().

Parameters
DOMDocument | DOMElement$node
string$tagName
Returns
DOMNodeList
See also
https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
https://dom.spec.whatwg.org/#dom-element-getelementsbytagname
Note
Note that unlike the spec this method is not guaranteed to return a DOMNodeList (which cannot be freely constructed in PHP), just a traversable containing DOMElements.

◆ getInnerHTML()

static Parsoid\Utils\DOMCompat::getInnerHTML ( DOMElement  $element)
static

Get innerHTML.

Parameters
DOMElement$element
Returns
string
See also
https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml

◆ getLastElementChild()

static Parsoid\Utils\DOMCompat::getLastElementChild ( DOMNode  $node)
static

Return the last child of the node that is an Element, or null otherwise.

Parameters
DOMDocument | DOMDocumentFragment | DOMElement$node
Returns
DOMElement|null
See also
https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild

◆ getNextElementSibling()

static Parsoid\Utils\DOMCompat::getNextElementSibling ( DOMNode  $node)
static

Return the first following sibling of the node that is an element, or null otherwise.

Parameters
DOMNode$node
Returns
DOMElement|null
See also
https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling

◆ getOuterHTML()

static Parsoid\Utils\DOMCompat::getOuterHTML ( DOMElement  $element)
static

Get outerHTML.

Parameters
DOMElement$element
Returns
string
See also
https://w3c.github.io/DOM-Parsing/#dom-element-outerhtml

◆ getPreviousElementSibling()

static Parsoid\Utils\DOMCompat::getPreviousElementSibling ( DOMNode  $node)
static

Return the last preceding sibling of the node that is an element, or null otherwise.

Parameters
DOMNode$node
Returns
DOMElement|null
See also
https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling

◆ getTitle()

static Parsoid\Utils\DOMCompat::getTitle ( DOMDocument  $document)
static

Get document title.

Parameters
DOMDocument$document
Returns
string
See also
https://html.spec.whatwg.org/multipage/dom.html#document.title

◆ hasAttributes()

static Parsoid\Utils\DOMCompat::hasAttributes ( DOMElement  $element)
static

Workaround bug in PHP's DOMElement::hasAttributes() that fails to enumerate attributes named xmlns.

Parameters
DOMElement$element
Returns
bool True if the element has any attributes
See also
https://phabricator.wikimedia.org/T235295

◆ normalize()

static Parsoid\Utils\DOMCompat::normalize ( DOMElement  $elt)
static
Parameters
DOMElement$eltroot of the DOM tree that needs to be normalized

◆ querySelector()

static Parsoid\Utils\DOMCompat::querySelector ( DOMNode  $node,
string  $selector 
)
static
Parameters
DOMDocument | DOMDocumentFragment | DOMElement$node
string$selector
Returns
DOMElement|null
See also
https://dom.spec.whatwg.org/#dom-parentnode-queryselector

◆ querySelectorAll()

static Parsoid\Utils\DOMCompat::querySelectorAll ( DOMNode  $node,
string  $selector 
)
static
Parameters
DOMDocument | DOMDocumentFragment | DOMElement$node
string$selector
Returns
DOMElement[]
See also
https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
Note
Note that unlike the spec this method is not guaranteed to return a DOMNodeList (which cannot be freely constructed in PHP), just a traversable containing DOMElements.

◆ remove()

static Parsoid\Utils\DOMCompat::remove ( DOMNode  $node)
static

Removes the node from the document.

Parameters
DOMElement | DOMCharacterData$node
See also
https://dom.spec.whatwg.org/#dom-childnode-remove

◆ setIdAttribute()

static Parsoid\Utils\DOMCompat::setIdAttribute ( DOMElement  $element,
string  $id 
)
static

Workaround bug in PHP's Document::getElementById() which doesn't actually index the 'id' attribute unless you use the non-standard DOMElement::setIdAttribute method after the attribute is set; see https://www.php.net/manual/en/domdocument.getelementbyid.php for more details.

Parameters
DOMElement$element
string$idThe desired value for the id attribute on $element.
See also
https://phabricator.wikimedia.org/T232390

◆ setInnerHTML()

static Parsoid\Utils\DOMCompat::setInnerHTML ( DOMElement  $element,
string  $html 
)
static

Set innerHTML.

See also
https://w3c.github.io/DOM-Parsing/#dom-innerhtml-innerhtml
Parameters
DOMElement$element
string$html

◆ setTitle()

static Parsoid\Utils\DOMCompat::setTitle ( DOMDocument  $document,
string  $title 
)
static

Set document title.

Parameters
DOMDocument$document
string$title
See also
https://html.spec.whatwg.org/multipage/dom.html#document.title

The documentation for this class was generated from the following file: