Share via


tagName Property

 

Contains the element name.

Script Syntax

strValue = oXMLDOMElement.tagName;  

Example

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

Visual Basic Syntax

strValue = oXMLDOMElement.tagName  

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">

Versioning

Implemented in:

MSXML 3.0, MSXML 6.0

Applies to

IXMLDOMElement