IVBMXNamespaceManager
Provides a convenient way to manage namespaces, namespace prefixes, and namespace URIs for an XML document. With IVBMXNamespaceManager, namespace contexts are organized as a stack of namespace declarations. Each push operation pushes a namespace declaration or set of namespace declarations onto the stack. Each pop operation discards everything from the top of the stack. Namespace declarations on the stack have both current and local context.
- Current context
- Set of all namespace declarations on the stack.
oNSMgr.declarePrefix("a", "urn:same uri");
oNSMgr.pushContext();
oNSMgr.declarePrefix("b", "urn:new uri");
The current context holds the prefixes "a" and "b".
- Local context
- Set of all namespace declarations from the top of the stack to the last
pushContext method.
oNSMgr.declarePrefix("a", "urn:same uri");
oNSMgr.pushContext();
oNSMgr.declarePrefix("b", "urn:new uri");
The local context holds the prefix "b".
The following example shows how to use IVBMXNamespaceManager to manage namespace declarations. Before you run the example, save the following XML code to a local drive as test.xml.
test.xml
<?xml version="1.0" ?>
<x xmlns:a="http://www.example.com/a" xmlns:b="http://www.example.com/a">
<y ref="a:firstele"/>
<y Name="b:firstele"/>
</x>
Option Explicit
Private Sub Dictionary_AddURIs()
Dim oNamedYs As IXMLDOMSelection
Dim oRefYs As IXMLDOMSelection
Dim oDomDoc As New DOMDocument40
Dim oNSMgr As New MXNamespaceManager40
Dim n As Variant
Dim varName As Variant
Dim strPrefix, strURI As String
oDomDoc.Load "c:\test.xml"
Set oNamedYs = oDomDoc.selectNodes("/x/y[@Name]")
Processes the nodes that have the attribute Name.
For Each n In oNamedYs
varName = n.getAttribute("Name")
strPrefix = Left(varName, InStr(varName, ":") - 1)
varName = Right(varName, Len(varName) - InStr(varName, ":"))
Uses the getURIFromNode method of NamespaceManager to get the URI from the declarations of the DOMDocument. This URI is used for the extracted prefix of the current DOM selection.
strURI = oNSMgr.getURIFromNode(strPrefix, n)
'User code to add a node to the dictionary.
Next
Processes the node that has the attribute ref.
Set oRefYs = oDomDoc.selectNodes("/x/y[@ref]")
For Each n In oRefYs
varName = n.getAttribute("ref")
strPrefix = Left(varName, InStr(varName, ":") - 1)
varName = Right(varName, Len(varName) - InStr(varName, ":"))
Uses the getURIFromNode method of NamespaceManager to get the URI from the declarations of the DOMDocument for the extracted prefix of the current DOM selection.
strURI = oNSMgr.getURIFromNode(strPrefix, n)
'User code to look up a name in the dictionary.
Next
End Sub
Remarks
IMXNamespaceManager provides duplicate methods for C++ processing, when necessary, to avoid the use of BSTR objects for C++.
IVBMXNamespaceManager performs a search from the top of stack through all namespace declarations, until a declaration is found or until the bottom of the stack is reached.
All indexes are continuous and start from 0.
IMXNamespaceManager checks [in] arguments for prefixes to ensure a valid prefix name according to the W3C Namespaces in XML Recommendation. IMXNamespaceManager does not check URI arguments.
Requirements
Implementation: msxml4.dll, msxml2.lib
[C/C++]
Header and IDL files: msxml2.h, msxml2.idl
Version-Dependent ProgID: MSXML2.MXNamespaceManager40
Version-Dependent CLSID: 88d969d6-f192-11d4-a65f-0040963251e5
Remarks
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.
See Also
IVBMXNamespaceManager Members | IMXNamespaceManager Members | IMXNamespacePrefixes
Other Resources 
W3C Namespaces in XML Recommendation