473,735 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing XML to a TreeView

Hi,

Consider i have an XML file like this:
<node type="item">
<user>MuZZy</user>
<password>Passw ord</password>
<node>
<node type="folder">
<node type="item">
<user>John</user>
<url>www.websit e.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 1447
MuZZy wrote:
Hi,

Consider i have an XML file like this:
<node type="item">
<user>MuZZy</user>
<password>Passw ord</password>
<node>
<node type="folder">
<node type="item">
<user>John</user>
<url>www.websit e.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!

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...;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

Jan 4 '06 #4

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

Similar topics

6
17308
by: Hans Kamp | last post by:
Is it possible to write a function like the following: string ReadURL(string URL) { .... } The purpose is that it reads the URL (determined by the parameter) and returns the string in which there is HTML-code, for example:
8
435
by: Fabio Cannizzo | last post by:
I have an XML file based on an XSD schema. It represents the content of a treeview (or a menu system), where the nodes are always of the same few types, but can be arbitrarily nested. I am writing my own recursive parser to read the file, but I wonder if there is some method ready to use provided by the .NET which does the job! Thanks
2
2104
by: hzgt9b | last post by:
I've written a simple javascript page that parses an XML file... (Actually I just modified the "Parsing an XML File" sample from http://www.w3schools.com/dom/dom_parser.asp) The page works great standalone... but when I try to make this work under frames I get "Error: Object required" when the following line executes: xmlDoc.getElementsByTagName("to"); The standalone file is named treeView.htm (attached). You should be
1
1943
by: doug9149 | last post by:
Hello all. I'm trying to parse data stored in XML format into my Windows application using C#. I'd like specific XML Nodes listed in a TreeView. When the TreeView Nodes are clicked I need corresponding XML data displayed in a different panel in the application using perhaps a DataGridView. Currently I have the TreeView part working. But I think I might be doing it inefficiently. I'm currently just traversing each XML Node through it's...
0
1550
by: doug9149 | last post by:
Hello all. I posted this in the .NET forum , but as it spans both groups I thought it might be best if I posted here too. I'm trying to parse data stored in XML format into my Windows application using C#. I'd like specific XML Nodes listed in a TreeView. When the TreeView Nodes are clicked I need corresponding XML data displayed in a different panel in the application using perhaps a DataGridView. Currently I have the TreeView part...
0
8783
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9323
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9193
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8196
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6747
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4555
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3269
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2186
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.