TreeView Data To Xml

  • Thread starter Thread starter Tiraman :-\)
  • Start date Start date
T

Tiraman :-\)

Hi,

i would like to save the treeview data (nodes) into an xml file.

how should i do that ?

Thanks.
 
If you just need something simple, try this. Note that this version doesn't
handle characters that must be escaped in XML, and it doesn't add the XML
header to the StringBuilder you're passing (you can append that before
calling the method, if you want it), but it should put you on the right
track. Pass it the TreeNode's root node (someTreeView.Nodes(0)) to save the
whole tree, or any branch node to save that branch.

Private Sub SaveAsXML(ByVal aTreeNode As TreeNode, ByVal sb As
StringBuilder)
sb.Append("<node><text>" & aTreeNode.Text & "</text>")
For Each tn As TreeNode In aTreeNode.Nodes
SaveAsXML(tn, sb)
Next
sb.Append("</node>")
End Sub
 
hi,

Thanks For The Example.



Russell Jones said:
If you just need something simple, try this. Note that this version doesn't
handle characters that must be escaped in XML, and it doesn't add the XML
header to the StringBuilder you're passing (you can append that before
calling the method, if you want it), but it should put you on the right
track. Pass it the TreeNode's root node (someTreeView.Nodes(0)) to save the
whole tree, or any branch node to save that branch.

Private Sub SaveAsXML(ByVal aTreeNode As TreeNode, ByVal sb As
StringBuilder)
sb.Append("<node><text>" & aTreeNode.Text & "</text>")
For Each tn As TreeNode In aTreeNode.Nodes
SaveAsXML(tn, sb)
Next
sb.Append("</node>")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top