Retrieves the attribute with the specified name.
var objXMLDOMNode = oXMLDOMNamedNodeMap.getNamedItem(name);
An object. Returns IXMLDOMNode
object for the specified attribute. Returns Nothing if the attribute node is not in this collection.
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); var nodeBook, nodeId; 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.attributes.getNamedItem("id"); alert(nodeId.value); }
Set objXMLDOMNode = oXMLDOMNamedNodeMap.getNamedItem(name)
An object. Returns an IXMLDOMNode
object for the specified attribute. Returns Nothing if the attribute node is not in this collection.
Dim xmlDoc As New Msxml2.DOMDocument50 Dim nodeBook As IXMLDOMElement Dim nodeId As IXMLDOMAttribute 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") If TypeName(nodeBook.Attributes.getNamedItem("id")) <> "Nothing" Then Set nodeId = nodeBook.Attributes.getNamedItem("id") MsgBox nodeId.Value Else 'No @id attribute in attributes collection. MsgBox "Could not find the @id attribute as " & _ in a <book id=''> element." End If End If
HRESULT getNamedItem( BSTR name, IXMLDOMNode **namedItem);
IXMLDOMNode
object for the specified attribute. Returns Null if the attribute node is not in this collection.namedItem
parameter is Null.IXMLDOMNode *pIXMLDOMNode = NULL; IXMLDOMNamedNodeMap *pIXMLDOMNamedNodeMap = NULL; BSTR bstrAttributeName = ::SysAllocString(_T("dateModified")); IXMLDOMElement *pIXMLDOMElement = NULL; IXMLDOMDocument *pIXMLDOMDocument = NULL; VARIANT varValue; 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_attributes(&pIXMLDOMNamedNodeMap); if(SUCCEEDED(hr) && pIXMLDOMNamedNodeMap) { hr = pIXMLDOMNamedNodeMap->getNamedItem(bstrAttributeName, &pIXMLDOMNode); if(SUCCEEDED(hr) && pIXMLDOMNode) { pIXMLDOMNode->get_nodeValue(&varValue); ::MessageBox(NULL, _bstr_t(varValue), _T("Item Value"), MB_OK); pIXMLDOMNode->Release(); pIXMLDOMNode = NULL; } pIXMLDOMNamedNodeMap->Release(); pIXMLDOMNamedNodeMap = NULL; } pIXMLDOMElement->Release(); pIXMLDOMElement = NULL; } ::SysFreeString(bstrAttributeName); bstrAttributeName = NULL; } catch(...) { if(bstrAttributeName) ::SysFreeString(bstrAttributeName); if(pIXMLDOMElement) pIXMLDOMElement->Release(); if(pIXMLDOMNamedNodeMap) pIXMLDOMNamedNodeMap->Release(); if(pIXMLDOMNode) pIXMLDOMNode->Release(); DisplayErrorToUser(); } // Release pIXMLDOMDocument when finished with it.
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: IXMLDOMNamedNodeMap