xml文档绑定某个属性值到treeview算法
原文发布时间为:2008-08-10 —— 来源于本人的百度文章 [由搬家工具导入]
using System.Xml;
protected void Button2_Click(object sender, EventArgs e)
{
string xmlpath = Server.MapPath("~/App_Data/dirList.xml");
if (File.Exists(xmlpath))
{
XmlDocument dom = new XmlDocument();
dom.Load(xmlpath);
TreeView1.Nodes.Clear();
BindXmlToTreeView(dom.DocumentElement.ChildNodes, TreeView1.Nodes);
}
else
{
Response.Write("<script>alert('XML文档不存在,请先创建')</script>");
}
}
protected void BindXmlToTreeView(XmlNodeList xmlnodes, TreeNodeCollection treeNodes)
{
foreach (XmlNode child in xmlnodes)
{
if (child.Attributes != null && child.Attributes.Count > 0)//这个判断很重要!
{
string treeText = child.Attributes["name"].Value;
TreeNode tn = new TreeNode(treeText);
treeNodes.Add(tn);
BindXmlToTreeView(child.ChildNodes, tn.ChildNodes);
}
}
}
-----------------------------------------
原算法:
private void populateTreeControl( System.Xml.XmlNode document, System.Windows.Forms.TreeNodeCollection nodes)
{
foreach (System.Xml.XmlNode node in document.ChildNodes)
{ // If the element has a value, display it;
// otherwise display the first attribute
// (if there is one) or the element name
// (if there isn't)
string text = (node.Value != null ? node.Value : (node.Attributes != null && node.Attributes.Count > 0) ? node.Attributes[0].Value : node.Name);
TreeNode new_child = new TreeNode(text);
nodes.Add(new_child);
populateTreeControl(node, new_child.Nodes);
}
}
xml文档绑定某个属性值到treeview算法的更多相关文章
- 使用JAXP对XML文档进行DOM解析
import java.io.FileOutputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers. ...
- XMLHelper类 源码(XML文档帮助类,静态方法,实现对XML文档的创建,及节点和属性的增、删、改、查)
以下是代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...
- XML文档操作集锦(C#篇)
在JSON没流行起来的时候xml一直作为程序存储配置信息的主流介质:特别是小型数据表方面还是不错的选择,所以经常涉及到的操作无非也就是增删改查,这篇博客主要是对这些对比较常用的操作做了个简单的总结 文 ...
- 根据Attribute值条件对XML文档进行修改
现手上有一个XML文档, 需要把"直接工序"改为"间接工序0". 你可以使用<对XML文档进行修改> http://www.cnblogs.com/ ...
- 用Castor 处理XML文档
——Castor可以完成Java和XML的相互转换 前面有介绍过json-lib这个框架,在线博文:http://www.cnblogs.com/hoojo/archive/2011/04/21/20 ...
- XML文档中的xmlns、xmlns:xsi和xsi:schemaLocation
文章转载自:https://yq.aliyun.com/articles/40353 相信很多人和我一样,在编写Spring或者Maven或者其他需要用到XML文档的程序时,通常都是将这些XML文档头 ...
- 关于XML文档的xmlns、xmlns:xsi和xsi:schemaLocation
https://yq.aliyun.com/articles/40353 ************************************* 摘要: 相信很多人和我一样,在编写Spring或者 ...
- Spring学习----- Spring配置文件xml文档的schema约束
1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- 关于Spring配置文件xml文档的schema约束
最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...
随机推荐
- Bootstrap历练实例:标签修饰
您可以使用修饰的 class label-default.label-primary.label-success.label-info.label-warning.label-danger 来改变标签 ...
- Race condition
在很多门课上都接触到race condition, 其中也举了很多方法解决这个问题.于是想来总结一下这些方法. Race condition 它旨在描述一个系统或者进程的输出依赖于不受控制的事件出现顺 ...
- OAuth认证协议中的HMACSHA1加密算法
<?php function hmacsha1($key,$data) { $blocksize=64; $hashfunc='sha1'; if (strlen($key)>$block ...
- JAVA基础篇—文件与流
处理字节流的抽象类 InputStream 是字节输入流的所有类的超类,一般我们使用它的子类,如FileInputStream等. OutputStream是字节输出流的所有类的超类,一般我们使用它的 ...
- 大小端测试C实现
int is_little_endian(void)//判断是否是小端的函数 { union check_fun { int a; char b; }u1; u1.a=;//先将1(实际上就是0x00 ...
- 通过Proxool配置访问数据库的要点
proxool 配置的时候有Proxool.properties 或者 Proxool.xml 两种方式初始化. 我的配置环境是 myEclipse10+tomcat6.0 + mysql5.0 . ...
- Mysql之数据库用户操作
查看用户: select host,user from mysql.user; //mysql库中user表,host为主机地址,user为用户名 mysql> select host,user ...
- 记一次WMS的系统改造(3)— 行进中的复盘
行进中的波折 革新总会面对一些阻力和风险,一种新的观念.一种新的模式要来替代既有的产品,从来都不是一件简单的事,在WMS改造这件事上我们一开始就提出两种概念货物驱动和任务驱动,并找到一个标杆产品Sla ...
- webdriver高级应用- 测试过程中发生异常或断言失败时进行屏幕截图
封装了三个类来实现这个功能: 1.DataUtil.py 用于获取当前的日期以及时间,用于生成保存截图文件的目录名,代码如下: #encoding=utf-8 import time from dat ...
- Leetcode8--->String to Integer(实现字符串到整数的转换)
题目: 实现字符串到整数的转换 解题思路: 下面给出这道题应该注意的一些细节: 1. 字符串“ 123 ” = 123: 2. 字符串“+123” = 123: 3. 字符串“-12 ...