Xml TreeView
来源:互联网 发布:mysql insert字段 编辑:程序博客网 时间:2024/05/22 18:50
By James Divine Download Source XmlTreeView.zip Article Description The application shown here was my first adventure into Xml in the .Net platform. My goal was to be able to reflect any Xml file into the Windows Forms TreeView control. I found various examples online, but none I found were suited for opening all Xml files, rather they were suited to one schema or another. The problem I ran into while writing this was more of a programming theory issue than a coding issue. This example deals with two instances of recursion, one for reading the Xml file in and one for adding the data correctly to the TreeView control. I am aware that this application reinvents the wheel, since Internet Explorer gives the exact same functionality, but I was more interested in learning how to work with Xml files within the .Net Platform, especially using the XmlDocument class and this seemed like a good start. The following code snippet shows the method I used to accomplish my goal. About the Author: James Divine (james@4divine.com) is a Senior Software Developer with over 12 years experience working with web programming, desktop application programming, server application programming and handheld device programming. He has been working in .Net and C# for more than two years. James currently holds a Microsoft Certified Professional certification and is working towards the MCSD. private void FillTree(XmlNode node, TreeNodeCollection parentnode){// End recursion if the node is a text typeif(node == null || node.NodeType == XmlNodeType.Text || node.NodeType == XmlNodeType.CDATA)return;TreeNodeCollection tmptreenodecollection = AddNodeToTree(node, parentnode);// Add all the children of the current node to the treeviewforeach(XmlNode tmpchildnode in node.ChildNodes){FillTree(tmpchildnode, tmptreenodecollection);}}private TreeNodeCollection AddNodeToTree(XmlNode node, TreeNodeCollection parentnode){TreeNode newchildnode = CreateTreeNodeFromXmlNode(node);// if nothing to add, return the parent itemif(newchildnode == null) return parentnode;// add the newly created tree node to its parentif(parentnode != null) parentnode.Add(newchildnode);return newchildnode.Nodes;}private TreeNode CreateTreeNodeFromXmlNode(XmlNode node){TreeNode tmptreenode = new TreeNode();if((node.HasChildNodes) && (node.FirstChild.Value != null)){tmptreenode = new TreeNode(node.Name);TreeNode tmptreenode2 = new TreeNode(node.FirstChild.Value);tmptreenode.Nodes.Add(tmptreenode2);}else if(node.NodeType != XmlNodeType.CDATA) {tmptreenode = new TreeNode(node.Name);}return tmptreenode;}
- Xml TreeView
- Treeview xml
- TreeView Xml
- 用XML填充TreeView
- 用.XML填充TreeView
- TreeView承载XML数据源
- XML动态加载TreeView
- 以XML 填充 TreeView
- TREEVIEW 绑定XML
- 通过XML构建TreeView
- TreeView绑定XML
- TreeView绑定xml
- treeview绑定xml
- TreeView 绑定XML文件
- TreeView和XML
- treeview绑定xml
- treeview绑定xml数据
- C#中xml写入treeview,treeview写入xml
- 【收藏】ASP教程:数据库操作类
- 流媒体相关
- 网络带宽与下载速度的误解
- sun的没落是悲还是喜?
- ARM系统基本文件格式
- Xml TreeView
- oracle 异常处理(转载)
- 分享一个自己写的httpWatch自动化测试工具
- JTAG 详解
- 深入剖析C#的多态
- Linux挂载网络共享文件夹
- VS2005(c#)项目调试问题解决方案集锦
- SSH,telnet终端中文显示乱码解决办法
- SUN被收购了。。。Unix——Center立马就发邮件。。。