XML DOM tutoria...login
XML DOM tutorial
author:php.cn  update time:2022-04-13 15:27:56

DOM Node


XML DOM - Node Object


Node Object

The Node object represents an individual node in the document tree.

The nodes here can be: element nodes, attribute nodes, text nodes, and all other node types mentioned in the Node Types chapter.

Please note that although all objects inherit the Node properties/methods used to handle parent nodes and child nodes, not all objects can contain parent nodes or child nodes. For example, a Text node may not contain child nodes, so adding child nodes to a text node may cause a DOM error.

Node object properties

PropertiesDescription
baseURIReturn the absolute base URI of the node.
childNodesReturns the node list of the node's child nodes.
firstChild Returns the first child node of the node.
lastChildReturns the last child node of the node.
localName Returns the local part of the node name.
namespaceURIReturns the namespace URI of the node.
nextSiblingReturns the node immediately after the element.
nodeName Returns the name of the node, according to its type.
nodeTypeReturns the type of node.
nodeValue Sets or returns the value of a node, according to its type.
ownerDocumentReturns the root element of the node (document object).
parentNode Returns the parent node of the node.
prefixSet or return the namespace prefix of the node.
previousSiblingReturns the node immediately before the element.
textContentSet or return the text content of the node and its descendants.

Node Object Method

MethodDescription
appendChild() Adds the new child node to the end of the node's child node list.
cloneNode()Clone node.
compareDocumentPosition()Compare the document positions of two nodes.
getFeature(feature,version)Returns a DOM object that can execute a specialized API with the specified feature and version.
getUserData(key)Returns the object associated with the key on the node. This object must first be set to this node by calling setUserData with the same key.
hasAttributes()If the node has attributes, return true, otherwise return false.
hasChildNodes()Returns true if the node has child nodes, otherwise returns false.
insertBefore()Insert a new child node before the existing child node.
isDefaultNamespace(URI)Returns whether the specified namespaceURI is default.
isEqualNode() Checks whether two nodes are equal.
isSameNode() Check whether two nodes are the same node.
isSupported(feature,version)Returns whether the specified feature is supported on this node.
lookupNamespaceURI()Returns the namespace URI matching the specified prefix.
lookupPrefix()Returns the prefix that matches the specified namespace URI.
normalize()Place all text nodes under the node (including attributes) into a "standard" format, in which only structures (such as elements, comments , processing instructions, CDATA sections, and entity references) to separate Text nodes, for example, there are neither adjacent Text nodes nor empty Text nodes.
removeChild()Delete child nodes.
replaceChild()Replace child node.
setUserData(key,data,handler)Associate the object to the key on the node.

php.cn