다음을 통해 공유


getQualifiedItem Method

 

Returns the attribute with the specified namespace and attribute name.

JScript Syntax

var objXMLDOMNode = oXMLDOMNamedNodeMap.getQualifiedItem(baseName, namespaceURI);  

Parameters

baseName
The string specifying the base name of the attribute, without namespace qualification.

namespaceURI
The string specifying the namespace prefix that qualifies the attribute name.

Return Value

An object. Returns the attribute node specified by the baseName and namespaceURI parameters. Returns Null if the attribute is not in the collection or if the item is not an attribute.

Example

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");  
var oNamedNodeMap, nodeBook;  
xmlDoc.async = false;  
xmlDoc.load("books.xml");  
if (xmlDoc.parseError.errorCode != 0) {  
   var myErr = xmlDoc.parseError;  
   WScript.Echo("You have error " + myErr.reason);  
} else {  
   nodeBook = xmlDoc.selectSingleNode("//book");  
   oNamedNodeMap = nodeBook.attributes;  
   WScript.Echo(oNamedNodeMap.getQualifiedItem("id", "").value);  
}  

Output

When used with the sample XML file (books.xml), this example returns "bk101", the value of the id attribute for the first instance of the <book> element in books.xml.

Visual Basic Syntax

Set objXMLDOMNode = oXMLDOMNamedNodeMap.getQualifiedItem
(baseName, namespaceURI)  

Parameters

baseName
The string specifying the base name of the attribute, without namespace qualification.

namespaceURI
The string specifying the namespace prefix that qualifies the attribute name.

Return Value

An object. Returns the attribute node specified by the baseName and namespaceURI parameters. Returns Null if the attribute is not in the collection or if the item is not an attribute.

Output

When used with the sample XML file (books.xml), this example returns "bk101", the value of the id attribute for the first instance of the <book> element in books.xml.

C/C++ Syntax

HRESULT getQualifiedItem(  
    BSTR baseName,  
    BSTR namespaceURI,  
    IXMLDOMNode **qualifiedItem);  

Parameters

baseName[in]
The base name of the attribute, without namespace qualification.

namespaceURI[in]
The namespace prefix that qualifies the attribute name.

qualifiedItem[out, retval]
The attribute node specified by the baseName and namespaceURI parameters. Returns Null if the attribute is not in the collection or if the item is not an attribute.

Return Values

S_OK
The value returned if successful.

S_FALSE
The value when returning Null.

E_INVALIDARG
The value returned if qualifiedItem is Null.

Example

IXMLDOMNode *pIXMLDOMNode = NULL;  
IXMLDOMNamedNodeMap *pIXMLDOMNamedNodeMap = NULL;  
BSTR bstrAttributeName = ::SysAllocString(_T("dateModified"));  
IXMLDOMElement *pIXMLDOMElement = NULL;  
VARIANT varValue;  
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(hr) ? 0 : throw hr;  
  
   if(pIXMLDOMElement)  
   {  
      hr = pIXMLDOMElement->get_attributes(&pIXMLDOMNamedNodeMap);  
      if(SUCCEEDED(hr) && pIXMLDOMNamedNodeMap)  
      {  
         hr = pIXMLDOMNamedNodeMap->getQualifiedItem(bstrAttributeName, NULL, &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.  

Remarks

This member is an extension of the Worldwide Web Consortium (W3C) Document Object Model (DOM).

Versioning

Implemented in: MSXML 3.0 and MSXML 6.0

Applies to

IXMLDOMNamedNodeMap