XML DOM | Element Object

XML DOM - Element Object


Hello folks! welcome back to a new section of our tutorial on XML DOM. In this tutorial post, we are going to be studying about the XML DOM Element Object.

The XML DOM elements can be defined as building blocks of XML. Elements behaves as containers to hold elements, attributes, text, media object or all of these. Whenever a parser parses an XML document against the well-formedness, the parser navigates through an element node. An element node contains the text within it which is called as the text node.

The XML DOM Element Object inherits the properties and methods of the Node object as the element object is also considered as a Node. Besides the node object properties and methods, it has the following methods and properties

Element Object Properties

The following table lists the attributes of the XML DOM Element Object -

AttributeTypeDescription
tagNameDOMStringIt gives the name of the tag for the specified element.
schemaTypeInfoTypeInfoIt represents the type information associated with this element.

Element Object Methods

The following table lists the methods of the XML DOM Element Object -

MethodsTypeDescription
getAttribute()DOMStringRetrieves the value of the attribute if exists for the specified element.
getAttributeNS()DOMStringRetrieves an attribute value by local name and namespace URI.
getAttributeNode()AttrRetrieves the name of the attribute node from the current element.
getAttributeNodeNS()AttrRetrieves an Attr node by local name and namespace URI.
getElementsByTagName()NodeListReturns a NodeList of all descendant Elements with a given tag name, in document order.
getElementsByTagNameNS()NodeListReturns a NodeList of all the descendant Elements with a given local name and namespace URI in document order.
hasAttribute()booleanReturns true when an attribute with a given name is specified on this element or has a default value, false otherwise.
hasAttributeNS()booleanReturns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
removeAttribute()No Return ValueRemoves an attribute by name.
removeAttributeNSNo Return ValueRemoves an attribute by local name and namespace URI.
removeAttributeNode()AttrSpecified attribute node is removed from the element.
setAttribute()No Return ValueSets a new attribute value to the existing element.
setAttributeNS()No Return ValueAdds a new attribute. If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be the value parameter.
setAttributeNode()AttrSets a new attribute node to the existing element.
setAttributeNodeNSAttrAdds a new attribute. If an attribute with that local name and that namespace URI is already present in the element, it is replaced by the new one.
setIdAttributeNo Return ValueIf the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute.
setIdAttributeNSNo Return ValueIf the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute.


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will be studying about XML DOM Element Object tagName 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.