Results 1 to 10 of 10

Thread: [RESOLVED] XML Writer - Loop through treeview

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] XML Writer - Loop through treeview

    Ola,

    I have a treeview with a couple of rows + cells. How do I loop through the treeview so it creates the XML.

    Code:
       <myxml>
          <name><&#37;=mytreeview.cells(1).text %></name>
          <description>A fixed description</description>
          <myval>
            <values><%=mytreeview.cells(2).text & ", " & <%=mytreeview.cells(3).text %></values>
          </myval>
        </myxml>
    so it should create a new within the xml for each row.
    Code:
       <myxml>
          <name>bla</name>
          <description>A fixed description</description>
          <myval>
            <values>bla, bla</values>
          </myval>
        </myxml>
    I hope someone understands what I'm trying to do.

    Thanks in advance.
    Last edited by Radjesh Klauke; May 22nd, 2012 at 02:44 PM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: XML Writer - Loop through treeview

    I'm a little lost. A TreeView has no cells property.

    However, I have an idea of what you want. The basic idea is generating XML from a list of strings:-
    vbnet Code:
    1. '
    2.         Dim names() As String = {"Adrian", "Spirit", "Anika", "Clare", "Dawn"}
    3.  
    4.         Dim xml = <Root>
    5.                       <Names><%= From N As String In names Select <name>
    6.                                                                       <%= N %>
    7.                                                                   </name> %>
    8.                       </Names>
    9.                   </Root>

    The above code produces this XML:-
    xml Code:
    1. <Root>
    2.   <Names>
    3.     <name>Adrian</name>
    4.     <name>Spirit</name>
    5.     <name>Anika</name>
    6.     <name>Clare</name>
    7.     <name>Dawn</name>
    8.   </Names>
    9. </Root>

    Hopefully, you can adapt it to your example.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: XML Writer - Loop through treeview

    Ola Niya. thanks for the reply. I'm using a 3rd party control that does have that functionality.
    I think that I can make it work now. Will let you know.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  4. #4

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: XML Writer - Loop through treeview

    Hmmm... I thought I had it...

    Okay. I'm trying to create a kml-file. An example of a kml file:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
       <folder>
          <placemark>
                <name>M.H.C. Olympia</name>
                <point>
                   <coordinates>3.84197,51.31808,0</coordinates>
                </point>
          </placemark>
          <placemark>
             <name>M.H.C. Vlissingen</name>
                <point>
                   <coordinates>3.56222,51.45759,0</coordinates>
                </point>
          </placemark>
       </folder>
    </kml>
    my treeview looks like:



    my partial code:
    vb.net Code:
    1. For Each x As Node In AdvTree1.Nodes
    2.    Dim nName() As String = {x.Cells(0).Text}
    3.    Dim nVal() As String = {x.Cells(1).Text}
    4.    Dim nVal2() As String = {x.Cells(2).Text}
    5.  
    6.    Dim doc As XDocument = _
    7.       <?xml version="1.0" encoding="utf-8"?>
    8.       <kml xmlns="http://www.opengis.net/kml/2.2">
    9.          <folder>
    10.             <placemark>
    11.                <%= From n As String In nName Select<name><%= nName %></name>%>
    12.                <description>blabla</description>
    13.                <point><%= From o As String In nVal Select
    14.                   <coordinates><%= nVal %></coordinates>%>
    15.                </point>
    16.             </placemark>
    17.          </folder>
    18.       </kml>
    19. Next
    This returns:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <folder>
        <placemark>
          <name xmlns="">Sexbierum</name>
          <description>blabla</description>
          <point>
            <coordinates xmlns="">53.218837</coordinates>
          </point>
        </placemark>
      </folder>
    </kml><?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <folder>
        <placemark>
          <name xmlns="">New York (USA)</name>
          <description>blabla</description>
          <point>
            <coordinates xmlns="">40.7143528</coordinates>
          </point>
        </placemark>
      </folder>
    </kml><?xml version="1.0" encoding="utf-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <folder>
        <placemark>
          <name xmlns="">Dummy</name>
          <description>blabla</description>
          <point>
            <coordinates xmlns="">31.500</coordinates>
          </point>
        </placemark>
      </folder>
    </kml>
    If you compare it with an official you can see it's totally wrong. Besides that how do I add the nVal2 in the coordinates?
    Last edited by Radjesh Klauke; May 23rd, 2012 at 04:32 AM.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  5. #5
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: XML Writer - Loop through treeview

    It looks right. What exactly is wrong with what you got ? What is it supposed to look like ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  6. #6
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: XML Writer - Loop through treeview

    Try something along these lines:

    vb.net Code:
    1. Dim doc As XDocument = <?xml version="1.0" encoding="utf-8"?>
    2.                        <kml xmlns="http://www.opengis.net/kml/2.2">
    3.                            <folder>
    4.                                <%= From node In TreeView1.Nodes
    5.                                    Select <placemark>
    6.                                               <name><%= node.Cells(0).Text %></name>
    7.                                               <point>
    8.                                                   <coordinates><%= String.Format("{0},{1},0",
    9.                                                                    node.Cells(1).Text,
    10.                                                                    node.Cells(2).Text) %></coordinates>
    11.                                               </point>
    12.                                           </placemark>
    13.                                %>
    14.                            </folder>
    15.                        </kml>
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  7. #7

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: XML Writer - Loop through treeview

    @Niya. See the first codebock in #4. The code I tried created a complete new "<?xml version="1.0" encoding="utf-8"?>" - line. Thank you for all the help m8. (+REP)

    Having 1 big issues with the code of Matt.
    n.cells.... -> Option Strict doesn't allow late binding
    When I add option strict off it works fine btw. Thanks you for that. Only this late binding needs to be resolved.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: XML Writer - Loop through treeview

    Quote Originally Posted by Radjesh Klauke View Post
    @Niya. See the first codebock in #4. The code I tried created a complete new "<?xml version="1.0" encoding="utf-8"?>" - line.
    Oh....Then the code MattP posted is closer to your code should look like. I don't know anything about that TreeView so I can't really comment on the late binding issue, but it looks like you are in a much better position now.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  9. #9
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: XML Writer - Loop through treeview

    From node In TreeNode1.Nodes is the problem as it's inferring node to be of type object. Change it to "node As SomeType In TreeView1.Nodes.Cast(Of SomeType)()" and it should solve the late binding problem.
    This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.

    The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.

  10. #10

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: XML Writer - Loop through treeview

    You're the best!!! Thanks.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

Posting Permissions

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



Click Here to Expand Forum to Full Width