getDeclaredPrefix Method (C++)

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XML Reference

getDeclaredPrefix Method (C++)

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. The index value for a prefix can change as the current context changes.

C/C++ Syntax

HRESULT _getDeclaredPrefix
    [in] long nIndex,
    [in, out] wchar_t* pwchPrefix,
    [in, out] int* ppchPrefix);

Parameters

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.
ppchPrefix[in,out]
The length of the prefix. On output (for successful calls), the returned buffer contains the length of the prefix string. If the buffer is NULL, only the required buffer size is returned.

C/C++ Return Values

S_OK
The value returned if successful.
E_FAIL
The value returned if the index is out of bounds.
E_XML_BUFFERTOOSMALL
The MSXML error code for insufficient return buffer length.
E_POINTER
The value returned if ppchPrefix is NULL.

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", 1, 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);

Remarks

Returns a prefix value stored in a character buffer that is a null-terminated wide string accompanied by the ppchPrefix parameter. The ppchPrefix parameter contains the size of the buffer on input and the length, not including the null character, of a result on output. If the pointer to the buffer is NULL, ppchPrefix contains the required buffer size.

See Also

Applies to: IMXNamespaceManager