Gets the attribute node.
var objXMLDOMAttribute = oXMLDOMElement.getAttributeNode(name);
An object. Returns IXMLDOMAttribute
with the supplied name, or Null if the named attribute cannot be found on this element.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var nodeBook, nodeId, sIdValue; 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"); nodeId = nodeBook.getAttributeNode("id"); sIdValue = nodeId.value; alert(sIdValue); }
Set objXMLDOMAttribute = oXMLDOMElement.getAttributeNode(name)
An object. Returns IXMLDOMAttribute
with the supplied name, or Null if the named attribute cannot be found on this element.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim nodeBook As IXMLDOMElement Dim nodeId As IXMLDOMAttribute Dim sIdValue As String 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") Set nodeId = nodeBook.getAttributeNode("id") sIdValue = nodeId.Value MsgBox sIdValue End If
HRESULT getAttributeNode( BSTR name, IXMLDOMAttribute **attributeNode);
IXMLDOMAttribute
object that is returned with the supplied name, or Null if the named attribute cannot be found on this element.BOOL DOMElementAttributeNode() { BOOL bResult = FALSE; BSTR bstrAttributeName = ::SysAllocString(_T("dateCreated")); IXMLDOMAttribute* pIXMLDOMAttribute = NULL; IXMLDOMElement *pIXMLDOMElement = 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(m_hr) ? 0 : throw hr; If(pIXMLDOMElement) { hr = pIXMLDOMElement->getAttributeNode(bstrAttributeName, &pIXMLDOMAttribute); if(SUCCEEDED(hr) && pIXMLDOMAttribute) { // Read node value and display . . . bResult = TRUE; pIXMLDOMAttribute->Release(); pIXMLDOMAttribute = NULL; } ::SysFreeString(bstrAttributeName); bstrAttributeName = NULL; pIXMLDOMElement->Release(); pIXMLDOMElement = NULL; } } catch(...) { if(bstrAttributeName) ::SysFreeString(bstrAttributeName); if(pIXMLDOMAttribute) pIXMLDOMAttribute->Release(); if(pIXMLDOMElement) pIXMLDOMElement->Release(); DisplayErrorToUser(); } return bResult; }
To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button in the upper-left corner of the page.
Applies to: IXMLDOMElement