Additional IXMLDOMNamedNodeMap Methods
Name | Description |
---|---|
getNamedItem (name) | Retrieves the node object with the specified name. This method is usually used to retrieve an attribute from an element. |
getQualifiedItem (baseName, namespace)* | Returns the node object with the specified baseName and namespace. |
removeNamedItem (name) | Removes the node object that has the specified name from the named node map. This method is usually used to remove an attribute. |
removeQualifiedItem (baseName, namespace)* | Removes the node object with the specified baseName and namespace. This method is usually used to remove attributes from the collection. |
setNamedItem (newNode) | Inserts a new node into the collection. If a node with the same name as the newNode already exists, it's replaced. |
To illustrate how to use the methods and properties of IXMLDOMNamedNodeMap, add another command button to the frmDOMTest form with the name cmdNamedNodeMap and the caption NamedNodeMap. Add the following code to the click event handler of the cmdNamedNodeMap button:
Private Sub cmdNamedNodeMap_Click() Dim objNamedNodeMap As IXMLDOMNamedNodeMap Dim objXMLDoc As DOMDocument Set objXMLDoc = New DOMDocument objXMLDoc.async = False objXMLDoc.Load ("c:\Books.xml") Set objNamedNodeMap = objXMLDoc.documentElement.Attributes Debug.Print _ "The root's first attribute node's basename is: " & _ objNamedNodeMap.Item(0).baseName Debug.Print "The number of root's attribute nodes is: " & _ objNamedNodeMap.length Debug.Print "The first node xml is: " & _ objNamedNodeMap.nextNode.xml Set objNamedNodeMap = _ objXMLDoc.documentElement.firstChild.firstChild.Attributes Debug.Print _ "The title element's attribute node's" & _ " basename is: " & objNamedNodeMap.Item(0).baseName Debug.Print "The number of the title element's " & _ "attribute nodes is: " & objNamedNodeMap.length Set objNamedNodeMap = Nothing Set objXMLDoc = Nothing End Sub
Once again, to move through the XML document you will begin by getting a reference to a document object. This time, you will use the attributes property of the document object to get a reference to the IXMLDOMNamedNodeMap interface. When you run this example and click the NamedNodeMap button, the results are as follows:
The root's first attribute node's basename is: northwind The number of the root's attribute nodes is: 1 The first node xml is:xmlns: northwind="www.northwindtraders.com/PO" The title element's attribute node's baseName is: language The number of the title element's attribute nodes is: 1
Thus, using the IXMLDOMDocument interface's attributes property and the IXMLDOMNamedNodeMap interface we are able to get information about the namespace and attribute nodes.