从XML文件的特定元素填充TreeView节点 [英] Populate TreeView nodes from specific elements of XML file

查看:84
本文介绍了从XML文件的特定元素填充TreeView节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

WinForm应用程序中的 XML 文件进行交互总是很有趣.好吧,这里我需要您的建议,以便从XML文件填充树视图控件中的节点.
而且,请让我知道,与 XML文件进行读写以及搜索特定数据的最佳方式.
提前谢谢.

问候,
Itz.Irsahd

Hi Guys,

Interaction with XML files from WinForm Applications is always interesting. Well, here I need your suggestions to populate node in tree view control from XML file.
And please let me know, the best way to interact with XML file for Reading and Writing as well as searching for specific data.
Thanks in advance.

Regards,
Itz.Irsahd

推荐答案

请参阅一些CP文章:
XML TreeView控件 [在TreeView控件中加载和保存XML [ ^ ]
将TreeView控件加载并保存到XML文件使用XmlTextWriter和XmlTextReader [ ^ ]

还可以查看 CodeProject搜索 [ ^ ]
Refer some CP Articles:
XML TreeView Control[^]
Loading and Saving XML to and from a TreeView Control[^]
Loading and Saving a TreeView control to an XML file using XmlTextWriter and XmlTextReader[^]

Also have a look on CodeProject Search[^]


您好,Irshad,希望对您有所帮助.
填充TreeView使用XML进行控制 [
hi Irshad, i hope this will help you.
Populate TreeView control using XML[^]
best of luck.


好吧,
场景在这里.
我已经在xml文件中预订了信息.
以及文件的结构如下:
Well,
The scenario is here.
I''ve books information in xml file.
And the structure of file as below:
<catalog>
 <book>
  <title />
  <author />
  <genre />
  <price />
  .
  .
 </book>
</catalog>



而且我需要将所有作者和书籍的类型归为两类(作者,按类型).
因此,我在Google的帮助下解决了这个问题:
我通过XElement加载文档.



And I need to get all the authors and genre of books under two groups (By Author, By Genre).
So, I figure this out by help of Google:
I load document via XElement.

XElement doc = XElement.Load(SourcFile );


并使用循环在作者"组下添加作者的值(例如).


and use loop to add values of author (for example) under the Author Group.

foreach (XElement author in doc.Descendants("author"))
 {
   NewNode = AuthorGroupNode.Nodes.Add(author.Value);
 }



所以,那个故事.但是,在这种解决方案中,有一点需要改进,那就是如果某些书的作者相同,则重复值.
这是下一个任务.

感谢您的时间.

问候,
Itz.Irshad



So, that'' the story. But in this solution there is one thing to improve which is repeated values if some books have same author.
It is next task to do.

Thanks for time.

Regards,
Itz.Irshad


这篇关于从XML文件的特定元素填充TreeView节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆