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 ...
随机推荐
- 点击按钮在表格的某一行下,在添加一行(HTML+JS)
使用js在指定的tr下添加一个新的一行newTr html代码: <table> <tr> <td>用户名:</td> <td><in ...
- C#基于联通短信Sgip协议构建短信网关程序
此软件基于中国联通Sgip协议程序接口,适合在中国联通申请了短信发送端口的公司使用.短信群发已经成为现在软件系统.网络营销等必不可少的应用工具.可应用在短信验证.信息群发.游戏虚拟商品购买.事件提醒. ...
- python特殊字符转义符号表示
- php读取不到https的域名
因测试环境php遇到无法正常读取到https的域名,但是域名配置了ssl证书,故做如下排查. php测试代码如下 $config['base_url'] = ''; #开启调试模式 #echo &qu ...
- 【Python高级工程师之路】入门+进阶+实战+爬虫+数据分析整套教程
点击了解更多Python课程>>> 全网最新最全python高级工程师全套视频教程学完月薪平均2万 什么是Python? Python是一门面向对象的编程语言,它相对于其他语言,更加 ...
- 多本Python极速入门最佳书籍,不可错过的Python学习资料!
Python作为现在很热门的一门编程语言,介于Python的友好,许多的初学者都将其作为首选,为了帮助大家更好的学习Python,我筛选了2年内优秀的python书籍,个别经典的书籍扩展到5年内. ...
- drf分页器
drf分页器 1.第一种分页: 类似于django中的分页 2.第二种分页: 偏移分页 3.第三种分页: 加密分页(查询速度快) 无法跳跃 基本参数 from rest_framework.pagin ...
- Applied Nonparametric Statistics-lec6
Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/8 前面都是对一两个样本的检查,现在考虑k个样本的情 ...
- local search——配图
- net clr via c sharp chap1-- note
Tag-> 托管代码 Tag-> .NET Framework 系统环境检测 Tag-> 设置平台 Tag-> 查询64或32位机 Tag-> IL编译成机器指令 Tag ...