Binds the namespace prefix with the namespace URI in the local context. You can set the allowOverride
property to control whether duplicate prefixes are allowed in the local context.
ObjNSManager.declarePrefix(prefix, namespaceURI);
None.
var oNSMgr; try { oNSMgr = new ActiveXObject("Msxml2.MXNamespaceManager.5.0"); oNSMgr.declarePrefix( "sample", "urn"); oNSMgr.declarePrefix ("a", "abc"); alert(oNSMgr.getDeclaredPrefixes.length); // 3 alert(oNSMgr.getDeclaredPrefixes[0]); // "sample" alert(oNSMgr.getURI("sample")); // "urn" alert(oNSMgr.getPrefixes("urn")[0]); // "sample" } catch(e) { alert("Error \n" + e); }
ObjNSManager.declarePrefix(prefix, namespaceURI)
None.
Dim oNSMgr As New Msxml2.MXNamespaceManager50 oNSMgr.declarePrefix "sample", "urn " oNSMgr.declarePrefix "a", "abc" MsgBox oNSMgr.getDeclaredPrefixes.length ' 3 MsgBox oNSMgr.getDeclaredPrefixes.Item(0) ' "sample" MsgBox oNSMgr.getPrefixes("urn:some uri").Item(0) ' "sample" MsgBox oNSMgr.getURI("sample") ' "urn"
HRESULT declarePrefix( BSTR prefix, BSTR namespaceURI);
pushContext
and allowOverride
property is VARIANT_TRUE (prefix is overridden).pushContext
and allowOverride
property is VARIANT_FALSE (prefix is not overridden).void SampleMXNameSpaceMgr_Prefixs() { MSXML2::IMXNamespaceManagerPtr PtrIMXNamespaceManager; HRESULT hres; TCHAR Buffer[100]; unsigned short WideCharBuffer[100]; int BufferLength = 100; try { PtrIMXNamespaceManager.CreateInstance _ (__uuidof(MSXML2::MXNamespaceManager50)); 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); }
The declarePrefix
method replaces the previous declaration if a prefix has already been declared in the local context and allowOverride
is enabled. The NamespaceURI
parameter should not be empty, unless it is used to redefine the default namespace with a namespace that contains an empty prefix. For example, the following is permitted:
nm.declarePrefix " "," "
But the following is not:
nm.declarePrefix "a"," "
The invalid prefixes "xml" and "xmlns" cannot be passed to this method.
An error is raised if the prefix is invalid, or if the namespace URI is empty, but its prefix is not.
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: IVBMXNamespaceManager
Applies to: IMXNamespaceManager
W3C Namespaces in XML Recommendation