Represents an attribute of the XMLDOMElement object. Valid and default values for the attribute are defined in a DTD or schema.
This interface inherits from IXMLDOMNode.
XMLDOMAttribute objects inherit the XMLDOMNode object but are not actually child nodes of the element and are not considered part of the document tree. Attributes are considered properties of their associated elements rather than independent and separate. Thus the object's parentNode, previousSibling, and nextSibling properties have the value Null.
Attribute nodes cannot be the immediate children of the XMLDOMDocumentFragment node. However, they can be associated with element nodes that are children of the XMLDOMDocumentFragment node.
In this object, the relationship between the value and specified properties can be summarized as follows: If the attribute has an assigned value in the document and the specified property is True, the value is the assigned value. If the attribute has no assigned value in the document and has a default value in the DTD, the specified property is False and the value is the default value in the DTD. If the attribute has no assigned value in the document and has a value of #IMPLIED in the DTD, the attribute does not appear in the structure model of the document.
In XML, the value of an attribute is represented by the child nodes of the attribute node because the value can contain entity references. Thus attributes that contain entity references will have a child list containing both text nodes and entity reference nodes. In addition, because the attribute type might be unknown, there are no tokenized attribute values.
_variant_t varValue; BSTR bstrAttributeName = ::SysAllocString(_T("dateCreated")); IXMLDOMElement *pIXMLDOMElement = NULL; IXMLDOMDocument *pIXMLDOMDocument = NULL; HRESULT hr; try { // Initialize pIXMLDOMDocument and load an // XML file into it. // Get the document root. 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; } RELEASE(pIXMLDOMElement); } ::SysFreeString(bstrAttributeName); bstrAttributeName=NULL; } catch(...) { if(bstrAttributeName) { ::SysFreeString(bstrAttributeName); bstrAttributeName = NULL; } CHECK_AND_RELEASE(pIXMLDOMElement); DisplayErrorToUser(); } // Release pIXMLDOMDocument when finished with it. Output ( in a message box ) Year 2000
Implementation: Msxml.dll
Header and IDL files: Msxml.h, Xmldom.idl