trizz
trizz

Reputation: 1447

Get XML tag by variable

I've got the following code in VB 2012, which returns a correct XML:

Dim xml = XDocument.Load("http://myURL.com/api/request")

I know I can use the values form the XML this way:

Debug.WriteLine(xml.<response>.<label1>.<regel1>.<text>.Value)

But the problem is, that label1 can also be label2, label3 etc. How can i create something like this:

For iLabel as Integer = 1 To myArray.Length
    Debug.WriteLine(xml.<response>.<label + iLabel>.<regel1>.<text>.Value)
Next

Upvotes: 0

Views: 51

Answers (1)

har07
har07

Reputation: 89285

How about using .Elements(XName) method, for example :

For iLabel as Integer = 1 To myArray.Length
    Debug.WriteLine(xml.<response>.Elements("label" & iLabel).<regel1>.<text>.Value)
Next

Upvotes: 1

Related Questions