XML DOM » Node » nodeName

Syntax:
node.nodeName

This property is read-only and contains the name of the node, depending on type.

The nodeName property is read-only and contains the name of the node, depending on type. This name is a string value and is never empty. The various types of name returned by each node are detailed below.

  • Element
    the name of the tag
  • Attr
    the name of the attribute
  • Text
    the literal string '#text'
  • CDATASection
    the literal string '#cdata-section'
  • EntityReference
    the name of the entity referenced
  • Entity
    the name of the entity
  • ProcessingInstruction
    the target, the first token following the characters <?
  • Comment
    the literal string '#comment'
  • Document
    the literal string '#document'
  • DocumentType
    the name of the document type
  • DocumentFragment
    the literal string '#document-fragment'
  • Notation
    the name of the notation

Examples

Code:
XML:

<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

JavaScript:

var xml_doc = new
ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("states.xml");

var n = xml_doc;
document.write(n.nodeName);
n = xml_doc.documentElement;
document.write("<br>" + n.nodeName);
Output:
#document
States
Explanation:

This example uses the 'states.xml' file and obtains the node names of the document itself, and of the document's root node.

Language(s): JavaScript XML