473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

XML issues: change name displayed in node

Through this link is an example of importing xml into a treeview in vb.net.

http://vb.net-informations.com/xml/v...w-from-xml.htm

I have this example working fine in vb.net 2008.

What I am having trouble with is how to change the name that displays in the node to an id that I set, or even the inner contents of the xml tags. Does anyone have any suggestions?
May 2 '13 #1
1 1123
I got past the node name by using inTreeNode.Text = inXmlNode.InnerText.ToString
This works, however it takes the very top node and edits the name of it to be the contents of every node below it.
Is there a way to skip the very top node?

If inTreeNode.Parent Is Nothing Then
'this is top level. do nothing
Else
inTreeNode.Text = inXmlNode.InnerText.ToString
End If


Expand|Select|Wrap|Line Numbers
  1.      Label1.Text = "File Path"
  2.         Label1.SetBounds(8, 8, 50, 20)
  3.         TextBox1.Text = Application.StartupPath() & "\Sample.xml"
  4.         Dim filename As String = Application.StartupPath() & "\Sample.xml"
  5.         TextBox1.SetBounds(64, 8, 256, 20)
  6.         Button1.Text = "Populate the TreeView with XML"
  7.         Button1.SetBounds(8, 40, 200, 20)
  8.         Me.Text = "TreeView control from XML"
  9.         Me.Width = 336
  10.         Me.Height = 368
  11.         TreeView1.SetBounds(8, 72, 312, 264)
  12.  
  13.         Dim xmldoc As New XmlDataDocument()
  14.         Dim xmlnode As XmlNode
  15.         Dim fs As New FileStream("Sample.xml", FileMode.Open, FileAccess.Read)
  16.         xmldoc.Load(fs)
  17.         xmlnode = xmldoc.ChildNodes(1)
  18.         TreeView1.Nodes.Clear()
  19.         TreeView1.Nodes.Add(New TreeNode(xmldoc.DocumentElement.Name))
  20.         Dim tNode As TreeNode
  21.         tNode = TreeView1.Nodes(0)
  22.         AddNode(xmlnode, tNode)
  23.     End Sub
  24.  
  25.     Private Sub AddNode(ByVal inXmlNode As XmlNode, ByVal inTreeNode As TreeNode)
  26.         Dim xNode As XmlNode
  27.         Dim tNode As TreeNode
  28.         Dim nodeList As XmlNodeList
  29.  
  30.         Dim i As Integer
  31.         Dim j As Integer = 0
  32.         If inXmlNode.HasChildNodes Then
  33.             nodeList = inXmlNode.ChildNodes
  34.             For i = 0 To nodeList.Count - 1
  35.                 xNode = inXmlNode.ChildNodes(i)
  36.                 inTreeNode.Nodes.Add(New TreeNode(xNode.Name))
  37.                 inTreeNode.Text = inXmlNode.InnerText.ToString
  38.                 tNode = inTreeNode.Nodes(i)
  39.                 AddNode(xNode, tNode)
  40.             Next
  41.         Else
  42.             inTreeNode.Text = " "
  43.         End If
  44.     End Sub
May 3 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom Loredo | last post by:
Hi folks- I'm about to move from a Solaris 8/SPARC environment to a Dell running RedHat 9. Are there any issues I need to be aware of in bringing my Python code over (mostly scientific...
28
by: grahamd | last post by:
Who are the appropriate people to report security problems to in respect of a module included with the Python distribution? I don't feel it appropriate to be reporting it on general mailing lists.
5
by: sandy | last post by:
Hi All, I am a newbie to MySQL and Python. At the first place, I would like to know what are the general performance issues (if any) of using MySQL with Python. By performance, I wanted to...
2
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
1
by: Aliandro | last post by:
Hi Does any one know where I can find information regarding any issues with SQL and IIS being run under windows XP SP2? as I am in the process of programmning in Dot net and neet some way of...
7
by: David Laub | last post by:
I have stumbled across various Netscape issues, none of which appear to be solvable by tweaking the clientTarget or targetSchema properties. At this point, I'm not even interested in "solving"...
2
by: G2 | last post by:
Hi We are dealing with significant browser compatibility issues with Netscape 5.x+ browsers and Mac IE. I am sure most web developers have faced similar issues in the past. Can anyone give me their...
1
by: GaryDean | last post by:
We have been developing all of our .net applications on 32 bit windows using 32 bit SQL Server. We are being asked to now deploy to servers running 64bit windows and 64bit SQL Server. Are there...
3
by: eschneider | last post by:
Just some common issues with WS: Using custom objects: When objects change, seems you are always fixing some issue. Update references, which sometimes does not work. Deployment: Weird errors...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.