Returns a collection of elements that have the specified name.
Syntax
objXMLDOMNodeList = oXMLDOMDocument.getElementsByTagName(tagname)
Parameters
- tagname
- String specifying the element name to find. The tagname "*" returns all elements in the document.
Returns
Object. Points to a collection of elements that match the specified name.
Remarks
The elements in the collection are returned in the order in which they would be encountered in a preorder traversal of the document tree. In a preorder traversal, the parent root node is visited first, and each child node from left to right is then traversed.
The returned XMLDOMNodeList object is live and immediately reflects changes to the nodes that appear in the list.
More complex searches can be performed using the selectNodes method, which may also be faster in some cases.
Example
The following example creates an XMLDOMNodeList object using the XMLDOMDocument object's getElementsByTagName method, then displays all of the elements with the desired tag name:
Dim ElemList Dim xmlDoc Set xmlDoc = CreateObject("microsoft.xmldom") xmlDoc.async = False xmlDoc.load("c:\books.xml") Set ElemList = xmlDoc.getElementsByTagName("AUTHOR") For i=0 To (ElemList.length -1) MsgBox (ElemList.item(i).xml) Next
Applies To
XMLDOMDocument