getPrefix Method (C++)

 

Finds the indexed prefix associated with the provided URI. Returns the indexed prefix in the current context. Used for enumeration, this method requests all available prefixes in the current context. The set of prefixes begins at 0. Note that the index value for a prefix can change as the current context changes.

C/C++ Syntax

HRESULT _getPrefix  
    [in] const wchar_t* pwszNamespaceURI,  
    [in] long nIndex,  
    [in, out] wchar_t* pwchPrefix,  
    [in, out] int* pcchPrefix);  

Parameters

pwszNamespaceURI[in]
The namespace URI associated with the prefix.

nIndex[in]
A long index value starting from 0.

pwchPrefix[in,out]
The returned prefix value. The buffer length on input contains the maximum length of the buffer. On output (for successful calls), the returned buffer contains the length of the prefix string. If the buffer is NULL, only the length is returned.

pcchPrefix[in,out]
The length of the prefix.

Return Values

S_OK
The value returned if successful.

E_INVALIDARG
The value returned if the pwszNamespaceURI parameter is an empty string or NULL. No prefix can be bound to an empty string.

E_FAIL
The value returned if the index is out of bounds. This return value implies that the prefix was not declared.

E_XML_BUFFERTOOSMALL
The MSXML error code for insufficient return buffer length.

E_POINTER
The value returned if ppchPrefix is NULL.

Remarks

Return values stored in a character buffer are null-terminated wide strings that are accompanied by the pcchPrefix parameter. The pcchPrefix, parameter specifies the length of the buffer on input, and returns the length of the result on output. The length of the result is returned as a null-terminated string in characters. If the pointer to the buffer is NULL, the getPrefix method returns only the length.

Example

MSXML2::IMXNamespaceManagerPtr PtrIMXNamespaceManager;
   HRESULT hres;
   TCHAR Buffer[100];
   unsigned short WideCharBuffer[100];
   int BufferLength = 100;

   try
   {
      PtrIMXNamespaceManager.CreateInstance( _
                              __uuidof(MSXML2::MXNamespaceManager));
      PtrIMXNamespaceManager->declarePrefix(_T("sample"),_T("urn"));
      PtrIMXNamespaceManager->declarePrefix(_T("a"),_T("abc"));
      
      _itot(PtrIMXNamespaceManager->getDeclaredPrefixes()->length, _
                                              Buffer, BufferLength);
      DisplayMessageToUser(Buffer);

      BufferLength = 100;
      PtrIMXNamespaceManager->_getDeclaredPrefix(2, WideCharBuffer, _
                              &BufferLength);
      DisplayMessageToUser(_bstr_t(WideCharBuffer));

      BufferLength = 100;
      PtrIMXNamespaceManager->_getPrefix(L"urn", 0, WideCharBuffer, _
                                         &BufferLength);
      DisplayMessageToUser(_bstr_t(WideCharBuffer));

      BufferLength = 100;
      hres = PtrIMXNamespaceManager->_getURI(L"sample", NULL, _
                                             WideCharBuffer, _
                                             &BufferLength);
      DisplayMessageToUser(_bstr_t(WideCharBuffer));
   }
   catch(...)
   {
      DisplayMessageToUser("Error");
   }
}

void DisplayMessageToUser(char *Msg)
{
    ::MessageBox(NULL, Msg, _T("Message"), MB_OK);
}

Versioning

Implemented in: MSXML 6.0

Applies to

IMXNamespaceManager