View Full Version : In VB.net how do I concatenate the varied value of 3 tags all with the same name?

04-24-2011, 01:57 AM
How do I concatenate all of the interests from the following XML file into one variable using vb.net 4.

<name>Paul Davis</name>

The VB code I have so far is as follows

Dim buffer As String

For Each itm In clients
If (itm.<name>.Value = CType(Session("Client"), String)) Then
Continue For
End If

buffer &= "<table><tr>"
buffer &= String.Format("<td>{0}</td>", itm.<name>.Value)
buffer &= String.Format("<td>{0}</td>", // The interests should be selected here
buffer &= "</tr></table>"

lblOutput.Text = buffer

04-25-2011, 03:57 PM
Hey NKeuxmuis,

I'm not quite sure how you're parsing the XML file. itm.<name>.Value? I've never seen that before :-) Anyway, you have to use the System.XML namespace (and I have a feeling you sort of are). But in any case, here is a sample:


You should get a pretty good idea from there. So now, all you have to do is just loop through each element inside the <client> element. Here is some pseudo code:

String s;
for each itm in clients
if itm.name = "interest" then
s += itm.value;
end if
Another thing, it's a bad practice to store tags inside a string for later output. If you need to create HTML tags dynamically, look into this sample:


You are able to create any HTML server control on the go.

There are also various data controls available to you, which act as a template, onto which you can directly bind data (XML or from a database). Here is a sample that applies to your situation:



09-08-2011, 04:32 PM
Hey Mike

Thanks for the informative link, actually I also have the been habituated of storing tag in strings. It gave me a lot of headache once while debugging but as all old habits die hard :-)

10-03-2011, 12:54 AM
hi do you make the codes by writting it or using a program