473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

treeview to XML file - urgent

IGotYourDotNet wrote:
I have a treeview on my for and I need to write all the nodes, parent,
child to an XML file, How can i do that?


Write a recursive function? Here's an example:
// read bookmarks
XmlTextReader xr=new
XmlTextReader(M ainForm.AppPath ()+"\\bookmarks .xml");
xr.Read();
TreeNode n=BookmarksForm .tvwbm.Nodes[0];
ReadBookmarkXML (ref xr,n);
xr.Close();
// write bookmarks
XmlTextWriter xr=new
XmlTextWriter(M ainForm.AppPath ()+"\\bookmarks .xml",System.Te xt.Encoding.UTF 8);
xr.Formatting=F ormatting.Inden ted;
xr.Indentation= 4;
xr.WriteStartDo cument();
WriteBookmarkXM L(ref xr,BookmarksFor m.tvwbm.Nodes[0]);
xr.WriteEndDocu ment();
xr.Flush();
xr.Close();
private static void ReadBookmarkXML (ref XmlTextReader xr, TreeNode n)
{
while (!xr.EOF)
{

try
{
xr.ReadStartEle ment("Node");
TreeNode m=new TreeNode(xr.Rea dElementString( "NodeName") );
if (haveReadRootBo okmark)
{
n.Nodes.Add(m);
n=m;
}
else
{
haveReadRootBoo kmark=true;
}
BookmarksForm.h ashRef[n.GetHashCode()]=xr.ReadElement String("Ref");
BookmarksForm.h ashText[n.GetHashCode()]=xr.ReadElement String("Text");
}
catch
{
//no more sub-nodes
xr.ReadEndEleme nt();
n=n.Parent;
}
}
}

private static void WriteBookmarkXM L(ref XmlTextWriter xr, TreeNode n)
{
xr.WriteStartEl ement("Node");
xr.WriteElement String("NodeNam e",n.Text);
xr.WriteElement String("Ref",(s tring)
BookmarksForm.h ashRef[n.GetHashCode()]);
xr.WriteElement String("Text",( string)
BookmarksForm.h ashText[n.GetHashCode()]);
foreach (TreeNode m in n.Nodes)
{
WriteBookmarkXM L(ref xr,m);
}
xr.WriteEndElem ent();
}
Nov 16 '05 #1
0 1034

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

Similar topics

4
3394
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
0
1761
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A product may consist of multiple other products. So far everything is great. But one product may exist as a subproduct to multiple parent products. ...
1
2087
by: | last post by:
What's the best way to create new nodes on a treeview 2.0 and save them to an xml file? Thanks, Victor
2
1588
by: SteveT | last post by:
Is there a way to locate the most recent node added to any location within a TreeView? -- ----------- Thanks, Steve
3
4063
by: =?Utf-8?B?TGVzbGll?= | last post by:
Using Visual Studio 2005 SP1 I am attempting to dynamically load a treeview control. I create an XmlDataSource and then load the data source using XmlDataSource.Data. I Load my XML string into this property using the code shown below. However if I change the values in the XML string that I am loading into XmlDataSource.Data and then run the...
1
1632
by: Rohit111111 | last post by:
Hello all, I have a treeview control just like windows file structure.I have a treeview control on the left side of page that will populate from database upto n-level,and on click of any node i am showing sub categories and files of selected category from the treenode,and on the right side of page i have a link add category that will redirect the...
4
3162
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
Hi, I am using VB.Net version 2 in a web application. I have a Navigation TreeView that is powered by a SiteMapDataSource linked to Web.sitemap file. This all works well. My questions is, how can I programatically hide a node based upon user roles? Thanks.
18
15346
by: =?Utf-8?B?TGkgV2VuZw==?= | last post by:
Hi, Is there a way for TreeView to have multiple selections? But I am not talking about its checked boxes. I want a way similar to ListView with MultiSelect = True. So I can use or key and click to make multiple selections. Then when I simply click one item, all previous selections are gone. Thanks in advance.
5
7506
by: Max2006 | last post by:
Hi, I have a TreeView and this is my node style: <asp:TreeNodeStyle ForeColor = "#000000" Font-Size="9px" Font-Bold="false" Width="100px" NodeSpacing="3px" /> The problem is the expand button (+) resides right at the middle of multi-line text. Can I make the expand button top align instead of middle align?
0
7541
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7979
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5385
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3512
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.