class DOMNode (View source)

The DOMNode class

Constants

DOCUMENT_POSITION_DISCONNECTED Since: 8.4

DOCUMENT_POSITION_PRECEDING Since: 8.4

DOCUMENT_POSITION_FOLLOWING Since: 8.4

DOCUMENT_POSITION_CONTAINS Since: 8.4

DOCUMENT_POSITION_CONTAINED_BY Since: 8.4

DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC Since: 8.4

Properties

string $nodeName
string|null $nodeValue
int $nodeType
DOMNode|null $parentNode
DOMNode> $childNodes
DOMNode|null $firstChild
DOMNode|null $lastChild
DOMNode|null $previousSibling
DOMNode|null $nextSibling
DOMAttr>|null $attributes
DOMDocument|null $ownerDocument
string|null $namespaceURI
string|null $prefix
string|null $localName
string|null $baseURI
string $textContent
bool $isConnected
DOMElement|null $parentElement

Methods

TNode|false
insertBefore(DOMNode $node, null|DOMNode $child = null)

Adds a new child before a reference node

TNode|false
replaceChild(DOMNode $node, DOMNode $child)

Replaces a child

TNode|false
removeChild(DOMNode $child)

Removes child from list of children

TNode|false
appendChild(DOMNode $node)

Adds new child at the end of the children

bool
hasChildNodes()

Checks if node has children

DOMNode|false
cloneNode(bool $deep = false)

Clones a node

void
normalize()

Normalizes the node

bool
isSupported(string $feature, string $version)

Checks if feature is supported for specified version

bool
hasAttributes()

Checks if node has attributes

int
compareDocumentPosition(DOMNode $other)

Compares the position of two nodes

bool
isSameNode(DOMNode $otherNode)

Indicates if two nodes are the same node

string|null
lookupPrefix(string $namespace)

Gets the namespace prefix of the node based on the namespace URI

bool
isDefaultNamespace(string $namespace)

Checks if the specified namespaceURI is the default namespace or not

string|null
lookupNamespaceURI(string|null $prefix)

Gets the namespace URI of the node based on the prefix

string|null
lookupNamespaceUri(string|null $prefix)

Gets the namespace URI of the node based on the prefix

bool
isEqualNode(DOMNode|null $otherNode)

Checks that both nodes are equal

getFeature($feature, $version)

No description

setUserData($key, $data, $handler)

No description

getUserData($key)

No description

string|null
getNodePath()

Gets an XPath location path for the node

int
getLineNo()

Get line number for a node

string|false
C14N(bool $exclusive = false, bool $withComments = false, null|array $xpath = null, null|array $nsPrefixes = null)

Canonicalize nodes to a string

int|false
C14NFile(string $uri, bool $exclusive = false, bool $withComments = false, null|array $xpath = null, null|array $nsPrefixes = null)

Canonicalize nodes to a file.

bool
contains(DOMNode|DOMNameSpaceNode|null $other)

Checks if node contains other node

getRootNode(array|null $options = null)

Get root node

array
__sleep()

Forbids serialization unless serialization methods are implemented in a subclass

void
__wakeup()

Forbids unserialization unless unserialization methods are implemented in a subclass

Details

TNode|false insertBefore(DOMNode $node, null|DOMNode $child = null)

Adds a new child before a reference node

Parameters

DOMNode $node

The new node.

null|DOMNode $child

[optional]

The reference node. If not supplied, newnode is appended to the children.

Return Value

TNode|false

The inserted node.

Exceptions

DOMException

TNode|false replaceChild(DOMNode $node, DOMNode $child)

Replaces a child

Parameters

DOMNode $node

The new node. It must be a member of the target document, i.e. created by one of the DOMDocument->createXXX() methods or imported in the document by .

DOMNode $child

The old node.

Return Value

TNode|false

The old node or false if an error occur.

Exceptions

DOMException

TNode|false removeChild(DOMNode $child)

Removes child from list of children

Parameters

DOMNode $child

The removed child.

Return Value

TNode|false

If the child could be removed the functions returns the old child.

Exceptions

DOMException

TNode|false appendChild(DOMNode $node)

Adds new child at the end of the children

Parameters

DOMNode $node

The appended child.

Return Value

TNode|false

The node added.

Exceptions

DOMException

bool hasChildNodes()

Checks if node has children

Return Value

bool

true on success or false on failure.

DOMNode|false cloneNode(bool $deep = false)

Clones a node

Parameters

bool $deep

Indicates whether to copy all descendant nodes. This parameter is defaulted to false.

Return Value

DOMNode|false

The cloned node.

void normalize()

Normalizes the node

Return Value

void

No value is returned.

bool isSupported(string $feature, string $version)

Checks if feature is supported for specified version

Parameters

string $feature

The feature to test. See the example of DOMImplementation::hasFeature for a list of features.

string $version

The version number of the feature to test.

Return Value

bool

true on success or false on failure.

bool hasAttributes()

Checks if node has attributes

Return Value

bool

true on success or false on failure.

int compareDocumentPosition(DOMNode $other)

Compares the position of two nodes

Compares the position of the other node relative to this node.

Parameters

DOMNode $other

Return Value

int

A bitmask of the DOMNode::DOCUMENTPOSITION* constants.

bool isSameNode(DOMNode $otherNode)

Indicates if two nodes are the same node

Parameters

DOMNode $otherNode

The compared node.

Return Value

bool

true on success or false on failure.

string|null lookupPrefix(string $namespace)

Gets the namespace prefix of the node based on the namespace URI

Parameters

string $namespace

The namespace URI.

Return Value

string|null

The prefix of the namespace.

bool isDefaultNamespace(string $namespace)

Checks if the specified namespaceURI is the default namespace or not

Parameters

string $namespace

The namespace URI to look for.

Return Value

bool

Return true if namespaceURI is the default namespace, false otherwise.

string|null lookupNamespaceURI(string|null $prefix)

Gets the namespace URI of the node based on the prefix

Parameters

string|null $prefix

The prefix of the namespace.

Return Value

string|null

The namespace URI of the node.

string|null lookupNamespaceUri(string|null $prefix)

Gets the namespace URI of the node based on the prefix

Parameters

string|null $prefix

The prefix of the namespace.

Return Value

string|null

The namespace URI of the node.

bool isEqualNode(DOMNode|null $otherNode)

Checks that both nodes are equal

Parameters

DOMNode|null $otherNode

The node.

Return Value

bool

Returns true if both nodes are equal, false otherwise.

getFeature($feature, $version)

No description

Parameters

$feature
$version

setUserData($key, $data, $handler)

No description

Parameters

$key
$data
$handler

getUserData($key)

No description

Parameters

$key

string|null getNodePath()

Gets an XPath location path for the node

Return Value

string|null

the XPath, or NULL in case of an error.

int getLineNo()

Get line number for a node

Return Value

int

Always returns the line number where the node was defined in.

string|false C14N(bool $exclusive = false, bool $withComments = false, null|array $xpath = null, null|array $nsPrefixes = null)

Canonicalize nodes to a string

Parameters

bool $exclusive

[optional] Enable exclusive parsing of only the nodes matched by the provided xpath or namespace prefixes.

bool $withComments

[optional] Retain comments in output.

null|array $xpath

[optional] An array of xpaths to filter the nodes by.

null|array $nsPrefixes

[optional] An array of namespace prefixes to filter the nodes by.

Return Value

string|false

Canonicalized nodes as a string or FALSE on failure

int|false C14NFile(string $uri, bool $exclusive = false, bool $withComments = false, null|array $xpath = null, null|array $nsPrefixes = null)

Canonicalize nodes to a file.

Parameters

string $uri

Path to write the output to.

bool $exclusive

[optional] Enable exclusive parsing of only the nodes matched by the provided xpath or namespace prefixes.

bool $withComments

[optional] Retain comments in output.

null|array $xpath

[optional] An array of xpaths to filter the nodes by.

null|array $nsPrefixes

[optional] An array of namespace prefixes to filter the nodes by.

Return Value

int|false

Number of bytes written or FALSE on failure

bool contains(DOMNode|DOMNameSpaceNode|null $other)

Since: 8.3

Checks if node contains other node

Parameters

DOMNode|DOMNameSpaceNode|null $other

Return Value

bool

DOMNode getRootNode(array|null $options = null)

Since: 8.3

Get root node

Parameters

array|null $options

Return Value

DOMNode

array __sleep()

Since: 8.1

Forbids serialization unless serialization methods are implemented in a subclass

Return Value

array

Exceptions

Error

void __wakeup()

Since: 8.1

Forbids unserialization unless unserialization methods are implemented in a subclass

Return Value

void

Exceptions

Error