XML, VB6 and Multiple nodeValues

Consider the following (theoretical and much-simplified) XML document:<XMLDoc>[INDENT]<XMLInfo>[INDENT]<XMLData type=“VALUE0”>I Don’t Want This</XMLData>
<XMLData type=“VALUE1”>I Do Want This</XMLData>
<XMLData type=“VALUE2”>I Don’t Want This</XMLData></XMLInfo>[/INDENT]</XMLDoc>[/INDENT]I know that the root (for want of a better word) tag for the above is /XMLDoc/XMLInfo/XMLData; but what I need is a method of extracting the text associated with the VALUE1 type, either by specifying the exact type (more efficient) or by navigating through the available values as one would an array or recordset (more interesting). I’m not looking for actual code, just a reference to information on the technique(s) involved.

(I find it semi-embarassing to ask for this sort of help. I’ve been working with VB for a number of years now, but my knowledge has been picked up on an “as-needed” basis—I’ve never had formal training. And up to this point, I’ve never had to deal with XML beyond a rudimentary level. What hurts more is that I consider myself moderately proficient in using search engines, and this problem defies every set of search criteria I’ve thrown at it.)

Anyway, any and all pointers and/or references much appreciated.

Techincally, the root of the document you included would just be: /XMLDoc


…is an xpath that would, in this case, resolve to a set of three nodes. So in your code, you’d be iterating through the node set. If you wanted to iterate through the ‘type’ attribute values, you could use this xpath:


If you wanted to iterate through the text content of the nodes:


If you wanted to match a specific node by type (let’s say the second one) and retrieve the text content:


Your third example provided exactly the syntax I needed! Adding the bracketed type to the tag allows the selectSingleNode method to zero in on the specific piece of data desired.

And I appreciate your clarifying the root tag (as I said, I only pick these things up as I go), as well as providing the other examples. When I have the time (ha!) maybe I’ll go back and explore some other approaches to the same problem.

Anyway, “much grass” as we used to say back in Montana in the '60s.[SUP]*[/SUP]

[SUP]*[/SUP]Must have been something in the water there & then.

Just in case it wasn’t clear from Sequent’s post, this is an example of XPATH syntax. XPATH is a query language designed to search XML documents and is programming-language neutral. You can find a decent tutorial here.

Tutorials are good. MG to you as well.

If you want to play around with XPath there’s an XPath Developer app available here. It allows you to play around with the XPaths, see what nodes they select, explore node axes etc.