vadao
asked on
XML Node Counting in MS Access VBA
How would I go about counting the number of nodes for a loaded XML document using MSXML2.DOMDocument60 in MS access VBA without using Xpath? I have tried the getelementsByTagName but I keep getting an error.
aikimark is correct, you can count nodes...
Something like :
Something like :
Dim objxmldoc As New MSXML2.DOMDocument60
Dim MyCount As MSXML2.IXMLDOMNodeList
open/load/namespace etc...
Set MyCount = objxmldoc.selectNodes("//ns1:yourtagtocount")
It would help if we could see your code so far...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Tweaking Ste5an's code...
Public Function GetCountOfNodesByTagNameList(ByVal parmXMLString, ByVal parmNodeTagList, Optional parmDelim = "^") As Long
Dim oDoc As Object
Dim vTag As Variant
Dim lngCount As Long
Set oDoc = CreateObject("MSXML2.DOMDocument")
oDoc.LoadXML parmXMLString
For Each vTag In Split(parmNodeTagList, parmDelim)
lngCount = lngCount + oDoc.getElementsByTagName(vTag).Length
Next
Set oDoc = Nothing
GetCountOfNodesByTagNameList = lngCount
End Function
Example of invoking the function, looking for nodes "a" and "b" and "root"?GetCountOfNodesByTagNameList("<root><a>1</a><a>2</a><b><a>3</a></b></root>","a^b^root")
5
Alternatively, you might iterate every node, keeping a tally of nodes as you traverse the tree.