471,354 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Parsing XML to a TreeView

Hi,

Consider i have an XML file like this:
<node type="item">
<user>MuZZy</user>
<password>Password</password>
<node>
<node type="folder">
<node type="item">
<user>John</user>
<url>www.website.com</url>
</node>
<node type = "folder">
<node type = "item">
<memo>free text</memo>
</node>
</node>
</node>
Here each <node> will be a TreeNode and the other tags like <user>,
<url>, <password> are some properties stored in the tree node. Nodes can
be of two types: "folder" and "item". "folder" can contain "item"'s
There can be unlimited nesting of <node> except that <node type="item">
can't contain any nodes, but <node type = "folder"> can.

So how do i parse it into a treeview? I am using a XmlTextReader nut it
reads the whole XML in line, so i can't really determine parent/chaild
relations between nodes.

I'm sure there is a standard way of doing that but i can't find one...
Any ideas?

Thank you,
MuZZy
Jan 4 '06 #1
3 1371
MuZZy wrote:
Hi,

Consider i have an XML file like this:
<node type="item">
<user>MuZZy</user>
<password>Password</password>
<node>
<node type="folder">
<node type="item">
<user>John</user>
<url>www.website.com</url>
</node>
<node type = "folder">
<node type = "item">
<memo>free text</memo>
</node>
</node>
</node>
Here each <node> will be a TreeNode and the other tags like <user>,
<url>, <password> are some properties stored in the tree node. Nodes can
be of two types: "folder" and "item". "folder" can contain "item"'s
There can be unlimited nesting of <node> except that <node type="item">
can't contain any nodes, but <node type = "folder"> can.

So how do i parse it into a treeview? I am using a XmlTextReader nut it
reads the whole XML in line, so i can't really determine parent/chaild
relations between nodes.

I'm sure there is a standard way of doing that but i can't find one...
Any ideas?

Thank you,
MuZZy

Actually. i got it! I just need to use XMLDocument instead
Jan 4 '06 #2
Hi,

Welcome to MSDN newsgroup!

In this scenario, I have performed your code and it seems work well. I
wonder whether the problem always is encountered when running the
application.

Otherwise, I suggest you run the application on other machines and find
whether the problem still occurs.

Thanks for your understanding!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Jan 4 '06 #3
Hi Muzzy,

Welcome to MSDN newsgroup!

Im glad to hear your problem has been resolved!

Additionally, the below KB article supplies some sample codes in for this
scenario:
http://support.microsoft.com/default...;en-us;Q317597

If you use ASP.Net v2.0, I think the XmlDataSource control is suitable. The
below article shows how to utilize ASP.NET v2.0:
http://aspalliance.com/671

I hope the above information will be helpful! If you have any concerns,
please feel free to let me know. Its my pleasure to be assistance!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support

Jan 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Hans Kamp | last post: by
8 posts views Thread by Fabio Cannizzo | last post: by
2 posts views Thread by hzgt9b | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.