How can I recursively parse through XML/XSL nodes?
Posted on 2003-10-27
I've built a small VB.NET app to parse through an XSL. It works, but only to a point, because I didn't program it recursively, so it is fairly limited.
What I'd like to be able to do is to parse down to an xsl:value-of node(which I can do), and then parse recursively
back up the line until I find the comment tag that belongs to it, and return the text in the comment.
I think I'd need a function that can take in both the XML nodelist and the current node that I'm working on.
This is what I've got so far for the function, but I can't get it to work yet:
Function getTarget(ByVal nList As XmlNodeList, ByVal node As XmlNode) As String
Dim target As String
Dim tmpNode As XmlNode
For Each tmpNode In nList
If tmpNode Is node Then
If tmpNode.NodeType.Comment Then
target = tmpNode.InnerText
MsgBox("Not a comment!")
tmpNode = tmpNode.ParentNode
target = getTarget(nList, tmpNode)
getTarget = target
Suggestions anyone? Thanks!