DOM Node Object - XML DOM

What is a Node object in XML DOM?

The primary data type used for the entire XML DOM is known as Node Interface. In the document tree, a single XML element is represented by the node.

Nodes are of different types – attribute node, text node or any other node. To get the node information, the attributes included are nodeName, nodeValue.

What are the attributes of a Node object?

The attributes of a node object are as follows:

Attribute
Type
Description
attributes
NamedNodeMap
This is of typeNamedNodeMapcontaining the attributes of this node (if it is an Element) or null otherwise.This has been removed. Referspecs
baseURI
DOMString
It is used to specify absolute base URI of the node.
childNodes
NodeList
It is aNodeListthat contains all children of this node. If there are no children, this is aNodeListcontaining no nodes.
firstChild
Node
It specifies the first child of a node.
lastChild
Node
It specifies the last child of a node.
localName
DOMString
It is used to specify the name of the local part of a node.This has been removed. Referspecs.
namespaceURI
DOMString
It specifies the namespace URI of a node.This has been removed. Referspecs
nextSibling
Node
It returns the node immediately following this node. If there is no such node, this returns null.
nodeName
DOMString
The name of this node, depending on its type.
nodeType
unsigned short
It is a code representing the type of the underlying object.
nodeValue
DOMString
It is used to specify the value of a node depending on their types.
ownerDocument
Document
It specifies theDocumentobject associated with the node.
parentNode
Node
This property specifies the parent node of a node.
prefix
DOMString
This property returns the namespace prefix of a node.This has been removed. Referspecs
previousSibling
Node
This specifies the node immediately preceding the current node.
textContent
DOMString
This specifies the textual content of a node.

What are the different Node Types?

The different types of Nodes are as follows:

  • ELEMENT_NODE
  • ATTRIBUTE_NODE
  • ENTITY_NODE
  • ENTITY_REFERENCE_NODE
  • DOCUMENT_FRAGMENT_NODE
  • TEXT_NODE
  • CDATA_SECTION_NODE
  • COMMENT_NODE
  • PROCESSING_INSTRUCTION_NODE
  • DOCUMENT_NODE
  • DOCUMENT_TYPE_NODE
  • NOTATION_NODE

What are the different Node object methods?

The different Node Object methods are tabulated below:

S.No.
Method & Description
1
appendChild(Node newChild)
This method adds a node after the last child node of the specified element node. It returns the added node.
2
cloneNode(boolean deep)
This method is used to create a duplicate node, when overridden in a derived class. It returns the duplicated node.
3
compareDocumentPosition(Node other)
This method is used to compare the position of the current node against a specified node according to the document order. Returnsunsigned short, how the node is positioned relatively to the reference node.
4
getFeature(DOMString feature, DOMString version)
Returns the DOM Object which implements the specialized APIs of the specified feature and version, if any, or null if there is no object.This has been removed. Referspecs.
5
getUserData(DOMString key)
Retrieves the object associated to a key on this node. The object must first have been set to this node by calling the setUserData with the same key. Returns the DOMUserData associated to the given key on this node, or null if there was none.This has been removed. Referspecs.
6
hasAttributes()
Returns whether this node (if it is an element) has any attributes or not. Returnstrue ifany attribute is present in the specified node else returnsfalse.This has been removed. Referspecs.
7
hasChildNodes()
Returns whether this node has any children. This method returnstrueif the current node has child nodes otherwisefalse.
8
insertBefore(Node newChild, Node refChild)
This method is used to insert a new node as a child of this node, directly before an existing child of this node. It returns the node being inserted.
9
isDefaultNamespace(DOMString namespaceURI)
This method accepts a namespace URI as an argument and returns aBooleanwith a value oftrueif the namespace is the default namespace on the given node orfalseif not.
10
isEqualNode(Node arg)
This method tests whether two nodes are equal. Returnstrueif the nodes are equal,falseotherwise.
11
isSameNode(Node other)
This method returns whether current node is the same node as the given one. Returnstrueif the nodes are the same,falseotherwise.This has been removed. Referspecs.
12
isSupported(DOMString feature, DOMString version)
This method returns whether the specified DOM module is supported by the current node. Returnstrueif the specified feature is supported on this node,falseotherwise.This has been removed. Referspecs.
13
lookupNamespaceURI(DOMString prefix)
This method gets the URI of the namespace associated with the namespace prefix.
14
lookupPrefix(DOMString namespaceURI)
This method returns the closest prefix defined in the current namespace for the namespace URI. Returns an associated namespace prefix if found or null if none is found.
15
normalize()
Normalization adds all the text nodes including attribute nodes which define a normal form where structure of the nodes which contain elements, comments, processing instructions, CDATA sections, and entity references separates the text nodes, i.e, neither adjacent Text nodes nor empty Text nodes.
16
removeChild(Node oldChild)
This method is used to remove a specified child node from the current node. This returns the node removed.
17
replaceChild(Node newChild, Node oldChild)
This method is used to replace the old child node with a new node. This returns the node replaced.
18
setUserData(DOMString key, DOMUserData data, UserDataHandler handler)
This method associates an object to a key on this node. The object can later be retrieved from this node by callinggetUserDatawith the same key. This returns theDOMUserDatapreviously associated to the given key on this node.This has been removed. Referspecs

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML DOM Topics