The DOMElement class

(PHP 5, PHP 7, PHP 8)

类摘要

class DOMElement extends DOMNode implements DOMParentNode, DOMChildNode {
/* 继承的常量 */
/* 属性 */
public readonly string $tagName;
public string $id;
public readonly mixed $schemaTypeInfo;
public readonly ?DOMElement $firstElementChild;
public readonly ?DOMElement $lastElementChild;
public readonly int $childElementCount;
/* 继承的属性 */
public readonly string $nodeName;
public readonly int $nodeType;
public readonly ?DOMNode $parentNode;
public readonly ?DOMElement $parentElement;
public readonly DOMNodeList $childNodes;
public readonly ?DOMNode $firstChild;
public readonly ?DOMNode $lastChild;
public readonly ?DOMNode $previousSibling;
public readonly ?DOMNode $nextSibling;
public readonly ?DOMNamedNodeMap $attributes;
public readonly bool $isConnected;
public readonly ?DOMDocument $ownerDocument;
public readonly ?string $namespaceURI;
public string $prefix;
public readonly ?string $localName;
public readonly ?string $baseURI;
/* 方法 */
public function __construct(string $qualifiedName, ?string $value = null, string $namespace = "")
public function after(DOMNode|string ...$nodes): void
public function append(DOMNode|string ...$nodes): void
public function before(DOMNode|string ...$nodes): void
public function getAttribute(string $qualifiedName): string
public function getAttributeNames(): array
public function getAttributeNode(string $qualifiedName): DOMAttr|DOMNameSpaceNode|false
public function getAttributeNodeNS(?string $namespace, string $localName): DOMAttr|DOMNameSpaceNode|null
public function getAttributeNS(?string $namespace, string $localName): string
public function getElementsByTagName(string $qualifiedName): DOMNodeList
public function getElementsByTagNameNS(?string $namespace, string $localName): DOMNodeList
public function hasAttribute(string $qualifiedName): bool
public function hasAttributeNS(?string $namespace, string $localName): bool
public function insertAdjacentElement(string $where, DOMElement $element): ?DOMElement
public function insertAdjacentText(string $where, string $data): void
public function prepend(DOMNode|string ...$nodes): void
public function remove(): void
public function removeAttribute(string $qualifiedName): bool
public function removeAttributeNode(DOMAttr $attr): DOMAttr|false
public function removeAttributeNS(?string $namespace, string $localName): void
public function replaceChildren(DOMNode|string ...$nodes): void
public function replaceWith(DOMNode|string ...$nodes): void
public function setAttribute(string $qualifiedName, string $value): DOMAttr|bool
public function setAttributeNode(DOMAttr $attr): DOMAttr|null|false
public function setAttributeNodeNS(DOMAttr $attr): DOMAttr|null|false
public function setAttributeNS(?string $namespace, string $qualifiedName, string $value): void
public function setIdAttribute(string $qualifiedName, bool $isId): void
public function setIdAttributeNode(DOMAttr $attr, bool $isId): void
public function setIdAttributeNS(string $namespace, string $qualifiedName, bool $isId): void
public function toggleAttribute(string $qualifiedName, ?bool $force = null): bool
/* 继承的方法 */
public function DOMNode::appendChild(DOMNode $node): DOMNode|false
public function DOMNode::C14N(
    bool $exclusive = false,
    bool $withComments = false,
    ?array $xpath = null,
    ?array $nsPrefixes = null
): string|false
public function DOMNode::C14NFile(
    string $uri,
    bool $exclusive = false,
    bool $withComments = false,
    ?array $xpath = null,
    ?array $nsPrefixes = null
): int|false
public function DOMNode::cloneNode(bool $deep = false): DOMNode|false
public function DOMNode::getLineNo(): int
public function DOMNode::getNodePath(): ?string
public function DOMNode::getRootNode(?array $options = null): DOMNode
public function DOMNode::hasAttributes(): bool
public function DOMNode::hasChildNodes(): bool
public function DOMNode::insertBefore(DOMNode $node, ?DOMNode $child = null): DOMNode|false
public function DOMNode::isDefaultNamespace(string $namespace): bool
public function DOMNode::isEqualNode(?DOMNode $otherNode): bool
public function DOMNode::isSameNode(DOMNode $otherNode): bool
public function DOMNode::isSupported(string $feature, string $version): bool
public function DOMNode::lookupNamespaceURI(?string $prefix): ?string
public function DOMNode::lookupPrefix(string $namespace): ?string
public function DOMNode::normalize(): void
public function DOMNode::removeChild(DOMNode $child): DOMNode|false
public function DOMNode::replaceChild(DOMNode $node, DOMNode $child): DOMNode|false
public function DOMNode::__sleep(): array
public function DOMNode::__wakeup(): void
}

属性

childElementCount

The number of child elements.

firstElementChild

First child element or null.

lastElementChild

Last child element or null.

nextElementSibling

The next sibling element or null.

previousElementSibling

The previous sibling element or null.

schemaTypeInfo

Not implemented yet, always return null

tagName

The element name

className

A string representing the classes of the element separated by spaces.

id

Reflects the element ID through the "id" attribute.

更新日志

版本 说明
8.3.0 The className and id properties and the DOMElement::getAttributeNames(), DOMElement::insertAdjacentElement(), DOMElement::insertAdjacentText(), and DOMElement::toggleAttribute() methods have been added.
8.0.0 The firstElementChild, lastElementChild, childElementCount, previousElementSibling, and nextElementSibling properties have been added.
8.0.0 DOMElement implements DOMParentNode and DOMChildNode now.

注释

注意: 此 DOM 扩展采用 UTF-8 编码。使用 mb_convert_encoding()UConverter::transcode()iconv() 来处理其它编码。

目录