473,386 Members | 1,752 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,386 software developers and data experts.

Save contents of treeview to XML

Hi all,

I have some problem while saving treeview's content to xml file. I have no experience dealing with xml file before. I did some leaning and searching on the web and found some sample codes in vb 6.0(i'm writing in vb.net). The code fails when tried to create a new XMLElement that consist of special characters like "&", "$", " "(space),etc.
Here's my code, perhaps anyone could advice me how solve this problem, or perhaps there's a better way to have this done.

Thanks

Yanto

Code:
Dim xmlDoc As New XmlDocument
Dim elementNode As XmlElement
Dim newElementNode As XmlElement
Dim rootElementNode As XmlElement

elementNode = xmlDoc.CreateElement("MyNode")
rootElementNode = xmlDoc.AppendChild(elementNode)

Dim iLp As Integer

For iLp = 0 To tvwCube.Nodes.Count - 1

elementNode = xmlDoc.CreateElement(tvwCube.Nodes(iLp).Text)
elementNode.SetAttribute("Caption", tvwCube.Nodes(iLp).Text)

newElementNode = rootElementNode.AppendChild(elementNode)

LoopChildren(tvwCube.Nodes(iLp), newElementNode)
Next iLp

xmlDoc.Save("C:\CubeMetadata.xml")
Private Sub LoopChildren(ByVal node As TreeNode, ByVal xNode As XmlNode)

Dim newChildElement As XmlElement
Dim newElementNode As XmlElement

Dim child As TreeNode
Dim strNode As String

For Each child In node.Nodes
'##### the code fails here, when there's a char like "$", "%","&" in strNode
newChildElement = xNode.OwnerDocument.CreateElement(strNode)
newChildElement.SetAttribute("Caption", child.Text)

newElementNode = xNode.AppendChild(newChildElement)

If child.GetNodeCount(False) > 0 Then
LoopChildren(child, newElementNode)
End If
Next child

End Sub
Nov 20 '05 #1
0 1859

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim P. | last post by:
I'm building a Task program. I've got the XMLTextReader working: opening & parsing the XML files, and propagating the TreeView with nodes & childs. But I don't know how to export out the contents...
1
by: R. Sammut | last post by:
Hi, I have a treeview control that is updated every 30 seconds. The treeview nodes are cleared and new nodes (same number of nodes and hierarchy) are added to the treeview. Now I need to save...
5
by: Robert Gale | last post by:
I am writing an RSS reader in C# and I'm trying to write the contents of a TreeView to an XML file. I have tried using XmlWriter and have managed to write simple tree structures but I get confused...
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
1
by: cjinsocal581 | last post by:
Hi all, I am struggling with the following: Environement: VB.NET 2005 TreeView Control SQL Database I need to be able to save a TreeView's nodes into a SQL database and then be able to call...
8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
3
by: serge calderara | last post by:
Dear all, I have a treeView control which is build with different parent and childs node objects. I try to find out an easy and proper way to save that nodes architecture in a XML file. Then...
2
by: Polaris | last post by:
Hi Experts: I'm using ASP.NET 2.0. I'm using a TreeView control with a design-time configured XmlDataSource (an XML file). I use the TreeView control as a "message board" with each node...
0
Ensonix
by: Ensonix | last post by:
I found a post about this, and it had some C# code that wouldn't convert, and when I finally got it converted it didn't work in .NET 1.1. So I made a few changes to the converted VB version and now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.