We now have a youtube channel. Subscribe!

XML DOM | Node Object

XML DOM | Node Object


Hello folks! welcome back to a new edition of our tutorial on XML DOM. In this tutorial post, we will be studying about XML DOM Node Object.

Node interface is the primary datatype for the entire Document Object Model. Node is used to represent a single XML element in the document tree.

Node can be any type, that is an attribute node, a text node, or any other node type. The attributes nodeName, nodeValue and attributes are added as mechanism to get at node information without casting down to the specific derived interface.


Attributes

Following table below lists the attributes of the Node object -

AttributeTypeDescription
attributesNamedNodeMapThis is of type NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
baseURIDOMStringIt is used to specify absolute base URI of the node.
childNodesNodeListIt is a NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
firstChildNodeIt specifies the first child of a node.
lastChildNodeIt specifies the last child of a node.
localNameDOMStringIt is used to specify the name of the local part of a node.
namespaceURIDOMStringIt specifies the namespace URI of a node.
nextSiblingNodeIt returns the node immediately following this node. If there is no such node, this returns null.
nodeNameDOMStringThe name of this node, depending on its type.
nodeTypeunsigned shortIt is a code representing the type of the underlying object.
nodeValueDOMStringIt is used to specify the value of a node depending on their types.
ownerDocumentDocumentIt specifies the Document object associated with the node.
parentNodeNodeThis property specifies the parent node of a node.
prefixDOMStringThis property returns the namespace prefix of a node.
previousSiblingNodeThis specifies the node immediately preceding the current node.
textContentDOMStringThis specifies the textual content of a node.


Node Types

The following below is a list of node types available in XML DOM -

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


Methods

The following table below lists the different Node Object methods -

S.No.Method & Description
1appendChild(Node newChild)

This method adds a node after the last child node of the specified element node. It returns the added node.

2cloneNode(boolean deep)

This method is used to create a duplicate node, when overridden in a derived class. It returns the duplicated node.

3compareDocumentPosition(Node other)

This method is used to compare the position of the current node against a specified node according to the document order. Returns unsigned 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.

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.

6

hasAttributes()

Returns whether this node (if it is an element) has any attributes or not. Returns true if any attribute is present in the specified node else returns false.

7hasChildNodes()

Returns whether this node has any children. This method returns true if the current node has child nodes otherwise false.

8insertBefore(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.

9isDefaultNamespace(DOMString namespaceURI)

This method accepts a namespace URI as an argument and returns a Boolean with a value of true if the namespace is the default namespace on the given node or false if not.

10isEqualNode(Node arg)

This method tests whether two nodes are equal. Returns true if the nodes are equal, false otherwise.

11

isSameNode(Node other)

This method returns whether current node is the same node as the given one. Returns true if the nodes are the same, false otherwise.

12

isSupported(DOMString feature, DOMString version)

This method returns whether the specified DOM module is supported by the current node. Returns true if the specified feature is supported on this node, false otherwise.

13lookupNamespaceURI(DOMString prefix)

This method gets the URI of the namespace associated with the namespace prefix.

14lookupPrefix(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.

15normalize()

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.

16removeChild(Node oldChild)

This method is used to remove a specified child node from the current node. This returns the node removed.

17replaceChild(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 calling getUserData with the same key. This returns the DOMUserData previouslyassociated to the given key on this node.



Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about XML DOM baseURI Attribute.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain