nodeName Property

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

nodeName Property

Returns the qualified name for attribute, document type, element, entity, or notation nodes. Returns a fixed string for all other node types. Read-only.

[Script]

Script Syntax

strValue = oXMLDOMNode.nodeName;

Example

The following script example creates an IXMLDOMNode object and displays its name.

var xmlDoc = new ActiveXObject5.0("Msxml2.DOMDocument.5.0");
var currNode;
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   currNode = xmlDoc.documentElement.childNodes.item(0);
   alert(currNode.nodeName);
}
[Visual Basic]

Visual Basic Syntax

strValue = oXMLDOMNode.nodeName

Example

The following Microsoft® Visual Basic® example creates an IXMLDOMNode object and displays its name.

Dim xmlDoc As New Msxml2.DOMDocument50
Dim currNode As IXMLDOMNode
xmlDoc.async = False
xmlDoc.Load ("books.xml")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   Set currNode = xmlDoc.documentElement.childNodes.Item(0)
   MsgBox currNode.nodeName
End If
[C/C++]

C/C++ Syntax

HRESULT get_nodeName(
    BSTR *name);

Parameters

name [out, retval]
Node name, which varies depending on the node type.

C/C++ Return Values

S_OK
Value returned if successful.
E_INVALIDARG
Value returned if the name parameter is Null.

Remarks

String. The property is read-only and always contains a non-empty string. The nodeName property contains the qualified name for the element, attribute, or entity reference. For example, it returns xxx:yyy for the element <xxx:yyy>.

The node name value varies, depending on the nodeType property.

NODE_ATTRIBUTE Contains the name of the attribute.
NODE_CDATA_SECTION Contains the literal string "#cdata-section".
NODE_COMMENT Contains the literal string "#comment".
NODE_DOCUMENT Contains the literal string "#document".
NODE_DOCUMENT_TYPE Contains the name of the document type; for example, xxx in <!DOCTYPE xxx ...>.
NODE_DOCUMENT_FRAGMENT Contains the literal string "#document-fragment".
NODE_ELEMENT Contains the name of the XML tag, with any namespace prefix included if present.
NODE_ENTITY Contains the name of the entity.
NODE_ENTITY_REFERENCE Contains the name of the entity referenced. Note that the name does not include the leading ampersand or the trailing semicolon. The name includes the namespace if one is present.
NODE_NOTATION Contains the name of the notation.
NODE_PROCESSING_INSTRUCTION Contains the target; the first token following the <? characters.
NODE_TEXT Contains the literal string "#text".

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

nodeType Property

Applies to: IXMLDOMAttribute | IXMLDOMCDATASection | IXMLDOMCharacterData | IXMLDOMComment | DOMDocument | IXMLDOMDocumentFragment | IXMLDOMDocumentType | IXMLDOMElement | IXMLDOMEntity | IXMLDOMEntityReference | IXMLDOMNode | IXMLDOMNotation | IXMLDOMProcessingInstruction | IXMLDOMText