tagName Property

MSXML 5.0 SDK

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

tagName Property

Contains the element name.

[Script]

Script Syntax

strValue = oXMLDOMElement.tagName;

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
var nodeBook, namedNodeMap;
xmlDoc.setProperty("SelectionLanguage", "XPath");
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   nodeBook = xmlDoc.selectSingleNode("//book");
   alert(nodeBook.tagName);
}
[Visual Basic]

Visual Basic Syntax

strValue = oXMLDOMElement.tagName

Example

Dim xmlDoc As New Msxml2.DOMDocument50
Dim nodeBook As IXMLDOMElement
Dim namedNodeMap As IXMLDOMNamedNodeMap
xmlDoc.setProperty "SelectionLanguage", "XPath"
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 nodeBook = xmlDoc.selectSingleNode("//book")
   MsgBox nodeBook.tagName
End If
[C/C++]

C/C++ Syntax

HRESULT get_tagName(
    BSTR *tagName);

Parameters

tagName [out, retval]
The string that represents the element's name.

C/C++ Return Values

S_OK
The value returned if successful.
S_FALSE
The value when returning Null.
E_INVALIDARG
The value returned if the tagName parameter is Null.

Example

IXMLDOMElement *pIXMLDOMElement = NULL;
BSTR bstrTagName = NULL;
IXMLDOMDocument *pIXMLDOMDocument = NULL;
HRESULT hr;

try
{
   // Create an instance of DOMDocument and initialize pIXMLDOMDocument.
   // Load/create an XML fragment.
   hr = pIXMLDOMDocument->get_documentElement(&pIXMLDOMElement);
   SUCCEEDED(hr) ? 0 : throw hr;

   if(pIXMLDOMElement)
   {
      hr = pIXMLDOMElement->get_tagName(&bstrTagName);
      if(SUCCEEDED(hr))
      {
         ::MessageBox(NULL, bstrTagName, _T("Tag Name"), MB_OK);
      }
      ::SysFreeString(bstrTagName);
      bstrTagName = NULL;
      pIXMLDOMElement->Release();
   }
}
catch(...)
{
   if(bstrTagName)
      ::SysFreeString(bstrTagName);
   if(pIXMLDOMElement)
      pIXMLDOMElement->Release();
   DisplayErrorToUser();
}

Remarks

String. The property is read-only. It contains the string that represents the element's name. For example, the tag name in the following tag is "book".

<book ISBN="1572318546">

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

Applies to: IXMLDOMElement