Parsing XML to a TreeView

M

MuZZy

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
 
M

MuZZy

MuZZy said:
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
 
Y

Yuan Ren[MSFT]

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
 
Y

Yuan Ren[MSFT]

Hi Muzzy,

Welcome to MSDN newsgroup!

I¡¯m 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.aspx?scid=kb;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. It¡¯s my pleasure to be assistance!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
 

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

Top