Traverse XML Document

G

Guest

I need a routine to search an entire XML document (all nodes) for a specified string & return the count (or return an arraylist of references to the nodes. I've tried various combinations of the code below, but somehow not all children or siblings are checked. I'm lost.

--Billg S

Public Function CountNodeValue(ByRef pNode As Xml.XmlNode, ByVal sValue As String) As Intege
Dim iCount As Intege

'Check siblings & childre
While Not pNode.FirstChild Is Nothing AndAlso Microsoft.VisualBasic.Left(pNode.FirstChild.Name, 1) <> "#
iCount = iCount + CountNodeValue(pNode.FirstChild, sValue
End Whil

While Not pNode.NextSibling Is Nothing AndAlso Microsoft.VisualBasic.Left(pNode.NextSibling.Name, 1) <> "#
iCount = iCount + CountNodeValue(pNode.NextSibling, sValue
End Whil

If UCase(Trim(pNode.Name)) = UCase(Trim(sValue)) The
iCount = iCount +
Els
' retrieve node.attributes for compariso
If Not pNode.Attributes Is Nothing The
For Each oItem In pNode.Attribute
If UCase(Trim(oItem.Name)) = UCase(Trim(sValue)) The
Debug.WriteLine("Match Found: " & sValue & "' = " & oItem.Name
iCount = iCount +
End I
Nex
End I
End I

Return iCoun
End Functio
 
Top