Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

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

    How do I concatenate all of the interests from the following XML file into one variable using vb.net 4.

    Code:
    <xml>
         <client>
              <name>Paul Davis</name>
              <interest>Football</interest>
              <interest>Swimming</interest>
              <interest>Internet</interest>
         </client>
    </xml>
    The VB code I have so far is as follows

    Code:
    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>"
    
    Next
    lblOutput.Text = buffer

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    244
    Thanks
    1
    Thanked 20 Times in 20 Posts
    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:

    http://www.codeproject.com/KB/cpp/parsefilecode.aspx

    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:

    Code:
    String s;
    for each itm in clients
     if itm.name = "interest" then
      s += itm.value;
     end if
    next
    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:

    http://www.w3schools.com/aspnet/control_htmltable.asp

    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:

    http://www.w3schools.com/aspnet/aspnet_repeater.asp

    Regards,
    Mike

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    21
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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 :-)

  • #4
    Banned
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi do you make the codes by writting it or using a program


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •