Returns a collection of elements that have the specified name.
Set objXMLDOMNodeList = oXMLDOMDocument.XMLDOMDocument(tagName)
HRESULT getElementsByTagName( BSTR tagName, IXMLDOMNodeList **resultList);
Returns S_OK if successful, or an error code otherwise.
The elements in the collection are returned in the order in which they would be encountered in a preorder traversal of the document tree. In a preorder traversal, the parent root node is visited first, and then each child node from left to right is traversed.
The returned DOMNodeList object is live and immediately reflects changes to the nodes that appear in the list.
More complex searches can be performed using the selectNodes method, which may also be faster in some cases.
IXMLDOMDocument *pIXMLDOMDocument = NULL; wstring strFindText (_T("AUTHOR")); IXMLDOMNodeList *pIDOMNodeList = NULL; IXMLDOMNode *pIDOMNode = NULL; long value; BSTR bstrItemText; HRESULT hr; try { // Initialize pIXMLDOMDocument (create a DOMDocument). // Load document. hr = pIXMLDOMDocument->getElementsByTagName( (TCHAR*)strFindText.data(), &pIDOMNodeList); SUCCEEDED(hr) ? 0 : throw hr; hr = pIDOMNodeList->get_length(&value); if(SUCCEEDED(hr)) { pIDOMNodeList->reset(); for(int ii = 0; ii < value; ii++) { pIDOMNodeList->get_item(ii, &pIDOMNode); if(pIDOMNode ) { pIDOMNode->get_text(&bstrItemText); ::MessageBox(NULL, bstrItemText,strFindText.data(), MB_OK); pIDOMNode->Release(); pIDOMNode = NULL; } } } pIDOMNodeList->Release(); pIDOMNodeList = NULL; } catch(...) { if(pIDOMNodeList) pIDOMNodeList->Release(); if(pIDOMNode) pIDOMNode->Release(); DisplayErrorToUser(); } // Release pIXMLDOMDocument when finished with it.