PHP 8.4.2 Released!

The Dom\Node class

(PHP 8 >= 8.4.0)

简介

This is the modern, spec-compliant equivalent of DOMNode.

类摘要

class Dom\Node {
/* 常量 */
public const int DOCUMENT_POSITION_DISCONNECTED = 0x1;
public const int DOCUMENT_POSITION_PRECEDING = 0x2;
public const int DOCUMENT_POSITION_FOLLOWING = 0x4;
public const int DOCUMENT_POSITION_CONTAINS = 0x8;
public const int DOCUMENT_POSITION_CONTAINED_BY = 0x10;
/* 属性 */
public readonly int $nodeType;
public readonly string $nodeName;
public readonly string $baseURI;
public readonly bool $isConnected;
public readonly ?Dom\Document $ownerDocument;
public readonly ?Dom\Node $parentNode;
public readonly ?Dom\Element $parentElement;
public readonly Dom\NodeList $childNodes;
public readonly ?Dom\Node $firstChild;
public readonly ?Dom\Node $lastChild;
public readonly ?Dom\Node $previousSibling;
public readonly ?Dom\Node $nextSibling;
/* 方法 */
/* Not documented yet */
}

预定义常量

DOMNode::DOCUMENT_POSITION_DISCONNECTED
Set when the other node and reference node are not in the same tree.
DOMNode::DOCUMENT_POSITION_PRECEDING
Set when the other node precedes the reference node.
DOMNode::DOCUMENT_POSITION_FOLLOWING
Set when the other node follows the reference node.
DOMNode::DOCUMENT_POSITION_CONTAINS
Set when the other node is an ancestor of the reference node.
DOMNode::DOCUMENT_POSITION_CONTAINED_BY
Set when the other node is a descendant of the reference node.
DOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC
Set when the result depends on implementation-specific behaviour and may not be portable. This may happen with disconnected nodes or with attribute nodes.

属性

nodeType

Gets the type of the node. One of the predefined XML_*_NODE constants

nodeName
Returns the most accurate name for the current node type.
  • For elements, this is the HTML-uppercased qualified name.
  • For attributes, this is the qualified name.
  • For processing instructions, this is the target.
  • For document type nodes, this is the name.
baseURI

The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.

isConnected

Whether the node is connected to a document

ownerDocument
The Dom\Document object associated with this node, or null if this node is a document.
parentNode

The parent of this node. If there is no such node, this returns null.

parentElement

The parent element of this element. If there is no such element, this returns null.

childNodes
A Dom\NodeList that contains all children of this node. If there are no children, this is an empty Dom\NodeList.
firstChild

The first child of this node. If there is no such node, this returns null.

lastChild

The last child of this node. If there is no such node, this returns null.

previousSibling

The node immediately preceding this node. If there is no such node, this returns null.

nextSibling

The node immediately following this node. If there is no such node, this returns null.

nodeValue
The value of this node, depending on its type.
textContent

The text content of this node and its descendants.

注释

注意: 此 DOM 扩展在处理方法或属性时使用 UTF-8 编码。 解析器方法会自动检测编码,或允许调用者指定编码。

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top