Retrieves the value of the named attribute.
strValue = oXMLDOMElement.getAttribute(name)
HRESULT getAttribute(
BSTR name,
VARIANT *value);
Another way to retrieve attributes is to use the XMLDOMNamedNodeMap object's getNamedItem method.
BOOL DOMElementAttribute()
{
BOOL bResult = FALSE;
_variant_t varValue;
BSTR bstrAttributeName = ::SysAllocString(_T("dateCreated"));
IXMLDOMDocument *pIXMLDOMDocument = NULL;
IXMLDOMElement *pIXMLDOMElement = 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)
{
varValue = _T("year 2000");
hr = pIXMLDOMElement->setAttribute(bstrAttributeName, varValue);
SUCCEEDED(hr) ? 0 : throw hr;
hr = pIXMLDOMElement->getAttribute(bstrAttributeName, &varValue);
SUCCEEDED(hr) ? 0 : throw hr;
if(varValue.vt != VT_NULL)
{
::MessageBox(NULL, _bstr_t(varValue), bstrAttributeName, MB_OK);
bResult = TRUE;
}
::SysFreeString(bstrAttributeName);
bstrAttributeName = NULL;
pIXMLDOMElement->Release();
}
}
catch(...)
{
if(bstrAttributeName)
::SysFreeString(bstrAttributeName);
if(pIXMLDOMElement)
pIXMLDOMElement->Release();
DisplayErrorToUser();
}
return bResult;
}